<jupyter_start><jupyter_text>CNN Architectures   COVIDx Dataset<jupyter_code>from fastai.vision.all import *
path = Path('/home/jupyter/covidx') 
torch.cuda.empty_cache()
# fix result 
def seed_everything(seed):
    random.seed(seed)
    os.environ['PYTHONHASHSEED'] = str(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)
    torch.cuda.manual_seed(seed)
    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = False
SEED = 42
seed_everything(SEED)
df = pd.read_csv(path/'covidx.csv')
df
get_x=lambda x:path/"images"/f"{x[1]}"
get_y=lambda x:x[2]
splitter=ColSplitter('is_valid')
bs = 32
metrics=[accuracy,  
         #RocAuc(average='macro', multi_class='ovr'),
         MatthewsCorrCoef(sample_weight=None),
         Precision(average='macro'),
         Recall(average='macro'),     
         F1Score(average='macro')] 
item_tfms=Resize(480, method='squish', pad_mode='zeros', resamples=(2, 0))
batch_tfms=[*aug_transforms(mult=1.0, do_flip=False, flip_vert=False, 
                            max_rotate=20.0, max_zoom=1.2, max_lighting=0.3, max_warp=0.2, 
                            p_affine=0.75, p_lighting=0.75, 
                            xtra_tfms=None, size=None, mode='bilinear', pad_mode='reflection', 
                            align_corners=True, batch=False, min_scale=1.0),
                            Normalize.from_stats(*imagenet_stats)]
db = DataBlock(blocks=(ImageBlock(cls=PILImageBW), CategoryBlock),
               get_x=get_x,
               get_y=get_y,
               splitter=splitter,
               item_tfms = item_tfms,
               batch_tfms=batch_tfms)
dl = db.dataloaders(df, bs=bs)<jupyter_output><empty_output><jupyter_text>Vgg16<jupyter_code>from torchvision.models import vgg16
arch = vgg16
learn = cnn_learner(dl, arch=arch, metrics=metrics)
learn.fine_tune(30)<jupyter_output><empty_output><jupyter_text>Vgg19<jupyter_code>from torchvision.models import vgg19
arch = vgg19
learn = cnn_learner(dl, arch=arch, metrics=metrics)
learn.summary()
learn.fine_tune(30)<jupyter_output><empty_output><jupyter_text>ResNet18<jupyter_code>arch = resnet18
learn = cnn_learner(dl, arch=arch, metrics=metrics)
learn.fine_tune(30)<jupyter_output><empty_output><jupyter_text>ResNet34<jupyter_code>arch = resnet34
learn = cnn_learner(dl, arch=arch, metrics=metrics)
learn.fine_tune(30)<jupyter_output><empty_output><jupyter_text>ResNet50<jupyter_code>arch = resnet50
learn = cnn_learner(dl, arch=arch, metrics=metrics)
learn.summary()
learn.fine_tune(30)<jupyter_output><empty_output><jupyter_text>Efficientnet-B0<jupyter_code>from efficientnet_pytorch import EfficientNet
arch = EfficientNet.from_pretrained("efficientnet-b0")
learn = Learner(dl, model=arch, metrics=metrics)
learn.fine_tune(30)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1261930010604454, 'fraction_numerical': 0.024390243902439025, 'mean_word_length': 4.549019607843137, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '201381', 'license': 'Apache-2.0', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1059, 'n_words': 128, 'path': 'CNN/.ipynb_checkpoints/arch-covidx-checkpoint.ipynb', 'repo_name': 'MaramMonshi/CovidXrayNet', 'size': '2829'}