<jupyter_start><jupyter_text>Multi Class<jupyter_code>MULTICLASS_CSV_PATH = DATA_PATH/'mc.csv'
mc = [set([row['class'] for index, row in img.object.iterrows()]) for img in images]
mcs = [' '.join(label for label in labels) for labels in mc]
print(mc[0:4])
print(mcs[0:4])
df = pd.DataFrame({'filename': [img.filename for img in images], 'class': mcs}, columns=['filename','class'])
df.to_csv(MULTICLASS_CSV_PATH, index=False)<jupyter_output><empty_output><jupyter_text>Train Round 1: Setup, Last Layer Only<jupyter_code>f_model=resnet34
sz=224
bs=16
tfms = tfms_from_model(f_model, sz, aug_tfms=transforms_side_on, max_zoom=1.1)
md = ImageClassifierData.from_csv(DATA_PATH, '', MULTICLASS_CSV_PATH, tfms=tfms, bs=bs)
learn = ConvLearner.pretrained(f_model, md, precompute=True)
learn.opt_fn = optim.Adam
lrf=learn.lr_find(1e-5,100)
learn.sched.plot(0)
lr = 2e-2
learn.fit(lr, 1, cycle_len=3, use_clr=(32,5)) 
# Since precompute=true, these first 3 epochs will not use dataaugmentation<jupyter_output><empty_output><jupyter_text>Train Round 2: All layers + Data Augmentation<jupyter_code>learn.precompute=False
# Take advantage of data augmentation
lrs = np.array([lr/9, lr/3, lr])
learn.unfreeze()
learn.lr_find(lrs/1000)
learn.sched.plot(0)
learn.fit(lrs/10, 1, cycle_len=10, use_clr=(32,5))
learn.save('mclas')
learn.load('mclas')<jupyter_output><empty_output><jupyter_text>Train round 3: Last Layer Only + Increase Input Size<jupyter_code>sz=299
bs=16

tfms = tfms_from_model(f_model, sz, aug_tfms=transforms_side_on, max_zoom=1.1)
md = ImageClassifierData.from_csv(DATA_PATH, '', MULTICLASS_CSV_PATH, tfms=tfms, bs=bs)

learn.set_data(md)
learn.freeze()
learn.lr_find(1e-5,100)
learn.sched.plot(0)
lr = 4e-3
learn.fit(lr, 1, cycle_len=5, use_clr=(32,5))
learn.save('mclas_299')
learn.load('mclas_299')<jupyter_output><empty_output><jupyter_text>Train Round 4: All layers + Larger Input Size<jupyter_code>lrs = np.array([lr/9, lr/3, lr])
learn.unfreeze()
learn.lr_find(lrs/1000)
learn.sched.plot(0)
learn.fit(lrs/10, 1, cycle_len=5, use_clr=(32,5))<jupyter_output><empty_output><jupyter_text>Let's show some predicitions<jupyter_code>y = predict(learn.model, learn.data.val_dl)
x,_ = next(iter(md.val_dl))
x = to_np(x)
fig, axes = plt.subplots(3, 4, figsize=(12, 8))
for i,ax in enumerate(axes.flat):
    image_data=md.val_ds.denorm(x)[i]
    ax = show_img(image_data, ax=ax)
    
    predicted_labels = np.nonzero(y[i]>0.4)[0]
    label_string = '\n'.join(md.classes[label] for label in predicted_labels)  
    draw_text(ax, (0,0), label_string)
    
    ground_labels = np.nonzero(_[i]>0)[0]
    ground_label_string = '\n'.join(md.classes[label] for label in ground_labels)  
    draw_text(ax, (50,0), ground_label_string)
    
plt.tight_layout()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15426105717367852, 'fraction_numerical': 0.03631787126932758, 'mean_word_length': 6.836619718309859, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '48650', 'license': 'Apache-2.0', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1159, 'n_words': 198, 'path': 'courses/dl2/roaddamage.ipynb', 'repo_name': 'drakesvoboda/fastai', 'size': '2781'}