Skip to content

Instantly share code, notes, and snippets.

View MercyMarkus's full-sized avatar

Mercy Markus MercyMarkus

View GitHub Profile
p,t = learn.get_preds(ds_type=DatasetType.Test)
p = to_np(p);
p.shape
ids = np.array([f.name for f in (combined_test)]);
ids.shape
sample_sub = Path('data/SampleSubmission.csv')
df_sample = pd.read_csv(sample_sub)
learn.fit_one_cycle(5, slice(1e-4))
tfms = get_transforms(flip_vert=True, max_lighting=0.1, max_zoom=1.05, max_warp=0.)
data = (src.transform(tfms, size=256)
.databunch().normalize(imagenet_stats))
learn.data = data
data.train_ds[0][0].shape
learn.fit_one_cycle(5, 1e-6)
tfms = get_transforms(flip_vert=True, max_lighting=0.1, max_zoom=1.05, max_warp=0.)
data = (src.transform(tfms, size=200)
.databunch().normalize(imagenet_stats))
learn.data = data
data.train_ds[0][0].shape
probs,val_labels = learn.get_preds(ds_type=DatasetType.Valid)
print('Accuracy',accuracy(probs,val_labels)),
print('Error Rate', error_rate(probs, val_labels))
print('AUC', auc_score(probs,val_labels))
learn.fit_one_cycle(7, max_lr=slice(1e-6,1e-4))
interp = ClassificationInterpretation.from_learner(learn)
interp.plot_confusion_matrix(dpi=120)
learn.save('resnet50-stg1')
from sklearn.metrics import roc_auc_score
def auc_score(y_score,y_true):
return torch.tensor(roc_auc_score(y_true,y_score[:,1]))
probs,val_labels = learn.get_preds(ds_type=DatasetType.Valid)
print('Accuracy',accuracy(probs,val_labels)),
print('Error Rate', error_rate(probs, val_labels))
print('AUC', auc_score(probs,val_labels))