This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! unzip labels.csv.zip | |
! unzip sample_submission.csv.zip | |
! unzip test.zip | |
! unzip train.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
labels_df=pd.read_csv(f'{PATH}labels.csv') | |
labels_df.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
label_csv=f'{PATH}labels.csv' | |
n=len(list(open(label_csv)))-1 | |
val_idxs=get_cv_idxs(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Total size",n) | |
print("Total validation size",len(val_idxs)) | |
#################### | |
#Total size 10222 | |
#Total validation size 2044 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sz=224 # size of image | |
arch=resnext101_64 # architecture used | |
bs=64 # batch size used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data= ImageClassifierData.from_csv(PATH,'train',f'{PATH}labels.csv',test_name='test', | |
val_idxs=val_idxs,suffix='.jpg',tfms=tfms_from_model(arch, sz),bs=64) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn=PATH+data.trn_ds.fnames[1] | |
fn | |
## '/content/clouderizer/dogbreed/data/competitions/dog-breed-identification/train/001cdf01b096e06d78e9e5112d419397.jpg' | |
img=PIL.Image.open(fn) | |
img | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img.size | |
##(500, 375) | |
# Mapping name of the file to size of the file | |
size_d={k:PIL.Image.open(PATH+k).size for k in data.trn_ds.fnames} | |
row_sz,col_sz=list(zip(*size_d.values())) | |
row_sz=np.array(row_sz) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
len(data.trn_ds),len(data.test_ds) | |
### (8178, 10357) | |
len(data.classes),data.classes[:5] | |
################################## | |
# (120, | |
# ['affenpinscher', | |
# 'afghan_hound', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_data(sz,bs): | |
tfms=tfms_from_model(arch, sz,aug_tfms=transforms_side_on,max_zoom=1.1) | |
data= ImageClassifierData.from_csv(PATH,'train',f'{PATH}labels.csv',test_name='test',num_workers=8, | |
val_idxs=val_idxs,suffix='.jpg',tfms=tfms,bs=bs) | |
return data if sz>300 else data.resize(340,'tmp') | |
data=get_data(sz,bs) |