Kaggle competition: Plant Pathology 2020 - FGVC7
def get_lr_callback(batch_size=8):
lr_start = 0.000005
lr_max = 0.00000125 * REPLICAS * batch_size
lr_min = 0.000001
lr_ramp_ep = 5
lr_sus_ep = 0
lr_decay = 0.8
def lrfn(epoch):
if epoch < lr_ramp_ep:
lr =(lr_max - lr_start)/ lr_ramp_ep * epoch + lr_start
elif epoch < lr_ramp_ep + lr_sus_ep:
lr = lr_max
else:
lr =(lr_max - lr_min)* lr_decay**(epoch - lr_ramp_ep - lr_sus_ep)+ lr_min
return lr
lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=False)
 return lr_callback<choose_model_class>
sub1 = pd.read_csv('.. /input/average-efficientnet/submission.csv')
 sub1.head()
def build_model(dim=512):
inp = tf.keras.layers.Input(shape=(dim,dim,3))
base = efn.EfficientNetB3(input_shape=(dim,dim,3),weights='imagenet',include_top=False)
 x = base(inp)
 x = tf.keras.layers.GlobalAveragePooling2D()(x)
 x = tf.keras.layers.Dense(1,activation='sigmoid' )(x)
 model = tf.keras.Model(inputs=inp,outputs=x)
 opt = tf.keras.optimizers.Adam(learning_rate=0.001)
 loss = tf.keras.losses.BinaryCrossentropy(label_smoothing=0.05)
 model.compile(optimizer=opt,loss=loss,metrics=['AUC'])
 return model<install_modules>
sub2 = pd.read_csv('.. /input/classification-densenet201-efficientnetb7/submission.csv')
 sub2.head()
!pip install yapl==0.1.2 efficientnet > /dev/null<choose_model_class>
sub3 = pd.read_csv('.. /input/tf-zoo-models-on-tpu/submission.csv')
 sub3.head()
input_shape =(512, 512, 3)
 def create_model() :
model = tf.keras.Sequential([
efn.EfficientNetB4(
 input_shape=input_shape,
weights='imagenet',
include_top=False 
),
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dense(1, activation='sigmoid')
 ])
 return model<define_variables>
sub4 = pd.read_csv('.. /input/fork-of-plant-2020-tpu-915e9c/submission.csv')
 sub4.head()
callbacks = [get_lr_callback(BATCH_SIZE)]
step_per_epoch = count_data_items(train_filenames)/BATCH_SIZE//REPLICAS<create_dataframe>
sub = pd.read_csv('.. /input/plant-pathology-2020-fgvc7/sample_submission.csv')
 sub.head()
test_dataset = get_test_dataset(ordered=True )<categorify>
sub.healthy =(sub1.healthy + sub2.healthy + sub3.healthy + sub4.healthy)/4
def get_dataset(filename, shuffle=False, repeat=False, return_img_name=False, augment=False, labeled=False, batch_size=32, dim=512):
dataset = tf.data.TFRecordDataset(filename, num_parallel_reads=AUTO)
 if repeat:
dataset = dataset.repeat()
if shuffle:
dataset = dataset.shuffle(1024*8)
 opt = tf.data.Options()
opt.experimental_deterministic = False
dataset = dataset.with_options(opt)
 if labeled:
dataset = dataset.map(read_labeled_tfrecord, num_parallel_calls=AUTO)
 else:
dataset = dataset.map(lambda example: read_unlabeled_tfrecord(example, return_img_name), num_parallel_calls=AUTO)
 dataset = dataset.map(lambda img, imgname_or_label:(decode_image(img, augment=augment), imgname_or_label), num_parallel_calls=AUTO)
 dataset = dataset.batch(batch_size * REPLICAS)
 dataset = dataset.prefetch(AUTO)
 return dataset<define_variables>
sub.multiple_diseases =(sub1.multiple_diseases + sub2.multiple_diseases + sub3.multiple_diseases + sub4.multiple_diseases)/4
FOLDS = 5
IMG_SIZE = 512
BATCH_SIZE = 32
EPOCHS = 12
weights = 1/6<choose_model_class>
sub.rust =(sub1.rust + sub2.rust + sub3.rust + sub4.rust)/4
kfold = KFold(n_splits=FOLDS, shuffle=True, random_state=0 )<load_pretrained>
sub.to_csv('submission.csv', index=False )
<concatenate><EOS> 
sub.to_csv('submission.csv', index=False )