Kaggle competition: Plant Pathology 2020 - FGVC7
<SOS> metric: MCAUC Kaggle data source: plant-pathology-2020-fgvc7<train_model>
import numpy as np
import pandas as pd
for layers in model_resnet.layers:
layers.trainable = True 
<choose_model_class>
sub1 = pd.read_csv('.. /input/classification-densenet201-efficientnetb7/submission.csv')
 sub2 = pd.read_csv('.. /input/tf-zoo-models-on-tpu/submission.csv')
 sub3 = pd.read_csv('.. /input/fork-of-plant-2020-tpu-915e9c/submission.csv')
 sub4 = pd.read_csv('.. /input/plant-pathology-2020-in-pytorch-0-979-score/submission.csv')
 submissions = [sub1, sub2, sub3, sub4]
sub_weights = [0.35, 0.10, 0.15, 0.40]
print(sum(sub_weights))
lr = 1e-3
optimizer = SGD(lr=lr, decay=1e-6, momentum=0.9, nesterov=True)
 model_resnet.compile(optimizer=optimizer, loss=keras.losses.categorical_crossentropy, metrics=['accuracy'])
 gc.collect() 
<train_model>
sub = pd.read_csv('.. /input/plant-pathology-2020-fgvc7/sample_submission.csv')
 sub.iloc[:, 1:] = np.average([df.iloc[:, 1:].values for df in submissions], weights=sub_weights, axis=0 )
history = model_resnet.fit_generator(generator=train_generator,
steps_per_epoch=NUB_TRAIN_STEPS,
validation_data=valid_generator,
validation_steps=NUB_VALID_STEPS,
epochs=NUM_EPOCHS,
callbacks=[eraly_stop, reduce_lr],
verbose=2)
 gc.collect() 
<create_dataframe>
def LabelSmoothing(encodings , alpha=0.01):
K = encodings.shape[1]
y_ls =(1 - alpha)* encodings + alpha / K
return y_ls
preds = sub.iloc[:, 1:].values
LabelSmoothing(preds, alpha=0.01)
 sub.iloc[:, 1:] = preds
test_datagen = ImageDataGenerator(rescale=1./ 255, validation_split=0.2, horizontal_flip=True)
 test_generator = test_datagen.flow_from_dataframe(dataframe=df_test,
directory=".. /input/aptos2019-blindness-detection/test_images/",
x_col="id_code",
target_size=(IMG_DIM, IMG_DIM),
batch_size=1,
shuffle=False,
class_mode=None,
seed=SEED)
 print(df_test.shape[0])
 gc.collect() 
<predict_on_test>
sub.to_csv('submission.csv', index=False )
<prepare_output><EOS> 
sub.to_csv('submission.csv', index=False )