Kaggle competition: SIIM-ISIC Melanoma Classification
<SOS> metric: MCAUC Kaggle data source: siim-isic-melanoma-classification<categorify>
!pip install -q efficientnet
y_train = keras.utils.to_categorical(y_train, num_classes)
 y_val = keras.utils.to_categorical(y_val, num_classes)
 y_train.shape, y_val.shape<choose_model_class>
import os
import re
import seaborn as sns
import numpy as np
import pandas as pd
import math
from matplotlib import pyplot as plt
from sklearn import metrics
from sklearn.model_selection import train_test_split
import tensorflow as tf
import tensorflow.keras.layers as L
import tensorflow.keras.backend as K
from tensorflow.keras.applications import DenseNet121, DenseNet201
import efficientnet.tfkeras as efn
from kaggle_datasets import KaggleDatasets
model = Sequential()
model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu', input_shape =(28,28,1)))
 model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu'))
model.add(MaxPool2D(pool_size=(2,2)))
 model.add(Dropout(0.25))
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
 model.add(Dropout(0.25))
model.add(Flatten())
 model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(10, activation = "softmax"))<choose_model_class>
AUTO = tf.data.experimental.AUTOTUNE
GCS_PATH = KaggleDatasets().get_gcs_path('melanoma-768x768')
 EPOCHS = 10
BATCH_SIZE = 8 * strategy.num_replicas_in_sync
IMAGE_SIZE = [768,768]
optimizer = keras.optimizers.RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0)
 model.compile(loss='categorical_crossentropy',
optimizer=optimizer,
metrics=['accuracy'] )<train_model>
HEIGHT = IMAGE_SIZE[0]
WIDTH = IMAGE_SIZE[1]
CHANNELS = 3
model.fit(X_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(X_val, y_val))<compute_test_metric>
def append_path(pre):
return np.vectorize(lambda file: os.path.join(GCS_DS_PATH, pre, file))
score = model.evaluate(X_val, y_val, verbose=0)
 score<predict_on_test>
sub = pd.read_csv('/kaggle/input/siim-isic-melanoma-classification/sample_submission.csv' )
results = model.predict(X_test)
 results = np.argmax(results, axis = 1)
 results = pd.Series(results, name="Label" )<save_to_csv>
train = pd.read_csv('/kaggle/input/siim-isic-melanoma-classification/train.csv' )
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"), results],axis = 1)
 submission.to_csv("cnn_mnist.csv",index=False )<install_modules>
TRAINING_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/train*.tfrec')
 TEST_FILENAMES = tf.io.gfile.glob(GCS_PATH + '/test*.tfrec')
 CLASSES = [0,1]
!pip install -q efficientnet_pytorch<import_modules>
def transform_rotation(image):
DIM = IMAGE_SIZE[0]
XDIM = DIM%2
rotation = 15.* tf.random.normal([1],dtype='float32')
 rotation = math.pi * rotation / 180.
 c1 = tf.math.cos(rotation)
 s1 = tf.math.sin(rotation)
 one = tf.constant([1],dtype='float32')
 zero = tf.constant([0],dtype='float32')
 rotation_matrix = tf.reshape(tf.concat([c1,s1,zero, -s1,c1,zero, zero,zero,one],axis=0),[3,3])
 x = tf.repeat(tf.range(DIM//2,-DIM//2,-1), DIM)
 y = tf.tile(tf.range(-DIM//2,DIM//2),[DIM])
 z = tf.ones([DIM*DIM],dtype='int32')
 idx = tf.stack([x,y,z])
 idx2 = K.dot(rotation_matrix,tf.cast(idx,dtype='float32'))
idx2 = K.cast(idx2,dtype='int32')
 idx2 = K.clip(idx2,-DIM//2+XDIM+1,DIM//2)
 idx3 = tf.stack([DIM//2-idx2[0,], DIM//2-1+idx2[1,]])
 d = tf.gather_nd(image, tf.transpose(idx3))
return tf.reshape(d,[DIM,DIM,3])
 def transform_shear(image):
DIM = IMAGE_SIZE[0]
XDIM = DIM%2
shear = 5.* tf.random.normal([1],dtype='float32')
 shear = math.pi * shear / 180.
 one = tf.constant([1],dtype='float32')
 zero = tf.constant([0],dtype='float32')
 c2 = tf.math.cos(shear)
 s2 = tf.math.sin(shear)
 shear_matrix = tf.reshape(tf.concat([one,s2,zero, zero,c2,zero, zero,zero,one],axis=0),[3,3])
 x = tf.repeat(tf.range(DIM//2,-DIM//2,-1), DIM)
 y = tf.tile(tf.range(-DIM//2,DIM//2),[DIM])
 z = tf.ones([DIM*DIM],dtype='int32')
 idx = tf.stack([x,y,z])
 idx2 = K.dot(shear_matrix,tf.cast(idx,dtype='float32'))
idx2 = K.cast(idx2,dtype='int32')
 idx2 = K.clip(idx2,-DIM//2+XDIM+1,DIM//2)
 idx3 = tf.stack([DIM//2-idx2[0,], DIM//2-1+idx2[1,]])
 d = tf.gather_nd(image, tf.transpose(idx3))
return tf.reshape(d,[DIM,DIM,3])
 def transform_shift(image):
DIM = IMAGE_SIZE[0]
XDIM = DIM%2
height_shift = 16.* tf.random.normal([1],dtype='float32')
 width_shift = 16.* tf.random.normal([1],dtype='float32')
 one = tf.constant([1],dtype='float32')
 zero = tf.constant([0],dtype='float32')
 shift_matrix = tf.reshape(tf.concat([one,zero,height_shift, zero,one,width_shift, zero,zero,one],axis=0),[3,3])
 x = tf.repeat(tf.range(DIM//2,-DIM//2,-1), DIM)
 y = tf.tile(tf.range(-DIM//2,DIM//2),[DIM])
 z = tf.ones([DIM*DIM],dtype='int32')
 idx = tf.stack([x,y,z])
 idx2 = K.dot(shift_matrix,tf.cast(idx,dtype='float32'))
idx2 = K.cast(idx2,dtype='int32')
 idx2 = K.clip(idx2,-DIM//2+XDIM+1,DIM//2)
 idx3 = tf.stack([DIM//2-idx2[0,], DIM//2-1+idx2[1,]])
 d = tf.gather_nd(image, tf.transpose(idx3))
return tf.reshape(d,[DIM,DIM,3])
 def transform_zoom(image):
DIM = IMAGE_SIZE[0]
XDIM = DIM%2
height_zoom = 1.0 + tf.random.normal([1],dtype='float32')/10.
 width_zoom = 1.0 + tf.random.normal([1],dtype='float32')/10.
 one = tf.constant([1],dtype='float32')
 zero = tf.constant([0],dtype='float32')
 zoom_matrix = tf.reshape(tf.concat([one/height_zoom,zero,zero, zero,one/width_zoom,zero, zero,zero,one],axis=0),[3,3])
 x = tf.repeat(tf.range(DIM//2,-DIM//2,-1), DIM)
 y = tf.tile(tf.range(-DIM//2,DIM//2),[DIM])
 z = tf.ones([DIM*DIM],dtype='int32')
 idx = tf.stack([x,y,z])
 idx2 = K.dot(zoom_matrix,tf.cast(idx,dtype='float32'))
idx2 = K.cast(idx2,dtype='int32')
 idx2 = K.clip(idx2,-DIM//2+XDIM+1,DIM//2)
 idx3 = tf.stack([DIM//2-idx2[0,], DIM//2-1+idx2[1,]])
 d = tf.gather_nd(image, tf.transpose(idx3))
return tf.reshape(d,[DIM,DIM,3] )
import time
import random
import datetime
import os
import numpy as np
import pandas as pd
from sklearn import model_selection
import torch
from torch import nn
from torch.utils.data import Dataset, DataLoader
import efficientnet_pytorch
import cv2
import albumentations as A
from albumentations.pytorch.transforms import ToTensorV2
import matplotlib.pyplot as plt<define_variables>
def data_augment_chaotic(image, label):
p_spatial = tf.random.uniform([1], minval=0, maxval=1, dtype='float32')
 p_spatial2 = tf.random.uniform([1], minval=0, maxval=1, dtype='float32')
 p_pixel = tf.random.uniform([1], minval=0, maxval=1, dtype='float32')
 p_crop = tf.random.uniform([1], minval=0, maxval=1, dtype='float32')
 if p_spatial >=.2:
image = tf.image.random_flip_left_right(image)
 image = tf.image.random_flip_up_down(image)
 if p_crop >=.7:
if p_crop >=.95:
image = tf.image.random_crop(image, size=[int(HEIGHT*.6), int(WIDTH*.6), CHANNELS])
 elif p_crop >=.85:
image = tf.image.random_crop(image, size=[int(HEIGHT*.7), int(WIDTH*.7), CHANNELS])
 elif p_crop >=.8:
image = tf.image.random_crop(image, size=[int(HEIGHT*.8), int(WIDTH*.8), CHANNELS])
 else:
image = tf.image.random_crop(image, size=[int(HEIGHT*.9), int(WIDTH*.9), CHANNELS])
 image = tf.image.resize(image, size=[HEIGHT, WIDTH])
 if p_spatial2 >=.6:
if p_spatial2 >=.9:
image = transform_rotation(image)
 elif p_spatial2 >=.8:
image = transform_zoom(image)
 elif p_spatial2 >=.7:
image = transform_shift(image)
 else:
image = transform_shear(image)
 if p_pixel >=.4:
if p_pixel >=.85:
image = tf.image.random_saturation(image, lower=0, upper=2)
 elif p_pixel >=.65:
image = tf.image.random_contrast(image, lower=.8, upper=2)
 elif p_pixel >=.5:
image = tf.image.random_brightness(image, max_delta=.2)
 else:
image = tf.image.adjust_gamma(image, gamma=.6)
 return image, label
SEED = 42<set_options>
def decode_image(image_data):
image = tf.image.decode_jpeg(image_data, channels=3)
 image = tf.cast(image, tf.float32)/ 255.0
image = tf.reshape(image, [*IMAGE_SIZE, 3])
 return image
def decode_image_file(file,label=None):
bits = tf.io.read_file(file)
 image = tf.image.decode_jpeg(bits,channels=3)
 image = tf.cast(image,tf.float32)/255.0
image = tf.reshape(image,[*IMAGE_SIZE,3])
 if label is None:
return image
return image,label
def read_labeled_tfrecord(example):
LABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"target": tf.io.FixedLenFeature([], tf.int64),
}
example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 label = tf.cast(example['target'], tf.int32)
 return image, label
def read_unlabeled_tfrecord(example):
UNLABELED_TFREC_FORMAT = {
"image": tf.io.FixedLenFeature([], tf.string),
"image_name": tf.io.FixedLenFeature([], tf.string),
}
example = tf.io.parse_single_example(example, UNLABELED_TFREC_FORMAT)
 image = decode_image(example['image'])
 idnum = example['image_name']
return image, idnum
def load_dataset(filenames, labeled=True, ordered=False):
ignore_order = tf.data.Options()
if not ordered:
ignore_order.experimental_deterministic = False
dataset = tf.data.TFRecordDataset(filenames, num_parallel_reads=AUTO)
 dataset = dataset.with_options(ignore_order)
 dataset = dataset.map(read_labeled_tfrecord if labeled else read_unlabeled_tfrecord, num_parallel_calls=AUTO)
 return dataset
def data_augment(image, label):
image = tf.image.random_flip_left_right(image)
 return image, label
def get_training_dataset() :
dataset = load_dataset(TRAINING_FILENAMES, labeled=True)
 dataset = dataset.map(data_augment, num_parallel_calls=AUTO)
 dataset = dataset.repeat()
dataset = dataset.shuffle(2048)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def get_validation_dataset(ordered=False):
dataset = load_dataset(VALIDATION_FILENAMES, labeled=True, ordered=ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.cache()
dataset = dataset.prefetch(AUTO)
 return dataset
def get_test_dataset(ordered=False):
dataset = load_dataset(TEST_FILENAMES, labeled=False, ordered=ordered)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset
def count_data_items(filenames):
n = [int(re.compile(r"-([0-9]*)\." ).search(filename ).group(1)) for filename in filenames]
return np.sum(n)
 NUM_TRAINING_IMAGES = count_data_items(TRAINING_FILENAMES)
 NUM_TEST_IMAGES = count_data_items(TEST_FILENAMES)
 STEPS_PER_EPOCH = NUM_TRAINING_IMAGES // BATCH_SIZE
print('Dataset: {} training images, {} unlabeled test images'.format(NUM_TRAINING_IMAGES, NUM_TEST_IMAGES))
def seed_everything(seed):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed(seed)
 torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = True
seed_everything(SEED )<set_options>
def build_lrfn(lr_start=0.00001, lr_max=0.0001,
lr_min=0.000001, lr_rampup_epochs=20,
lr_sustain_epochs=0, lr_exp_decay=.8):
lr_max = lr_max * strategy.num_replicas_in_sync
def lrfn(epoch):
if epoch < lr_rampup_epochs:
lr =(lr_max - lr_start)/ lr_rampup_epochs * epoch + lr_start
elif epoch < lr_rampup_epochs + lr_sustain_epochs:
lr = lr_max
else:
lr =(lr_max - lr_min)* lr_exp_decay**(epoch - lr_rampup_epochs - lr_sustain_epochs)+ lr_min
return lr
return lrfn
class DataLoaderConfig:
batch_size = 64
num_workers = 8
class TrainConfig:
criterion = nn.CrossEntropyLoss
n_epochs = 10
lr = 0.001
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau
scheduler_params = dict(
 mode='min',
factor=0.5,
patience=1,
verbose=False,
threshold=0.0001,
threshold_mode='abs',
cooldown=0,
min_lr=1e-8,
eps=1e-08 
)
 DEVICE = torch.device('cuda')if torch.cuda.is_available() else torch.device('cpu' )<load_from_csv>
with strategy.scope() :
model = tf.keras.Sequential([
efn.EfficientNetB3(
 input_shape=(*IMAGE_SIZE, 3),
weights='imagenet',
include_top=False 
),
L.GlobalAveragePooling2D() ,
L.Dense(512, activation='relu'),
L.Dense(128,activation='relu'),
L.Dense(1, activation='sigmoid')
 ])
 model.compile(
 optimizer='adam',
loss = 'binary_crossentropy',
metrics=['accuracy'] 
)
 model.summary()
df = pd.read_csv('.. /input/digit-recognizer/train.csv')
 print(df.shape)
 df.head()<prepare_x_and_y>
with strategy.scope() :
model2 = tf.keras.Sequential([
efn.EfficientNetB3(
 input_shape=(*IMAGE_SIZE, 3),
weights='imagenet',
include_top=False 
),
L.GlobalAveragePooling2D() ,
L.Dense(512, activation='relu'),
L.Dropout(0.3),
L.Dense(256, activation='relu'),
L.Dropout(0.25),
L.Dense(128, activation='relu'),
L.Dropout(0.2),
L.Dense(1, activation='sigmoid')
 ])
 model2.compile(
 optimizer='adam',
loss = 'binary_crossentropy',
metrics=['accuracy'] 
)
 model2.summary()
y = df['label'].values
X = df.drop(['label'], axis=1 ).values<split>
lrfn = build_lrfn()
lr_schedule = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=1)
 STEPS_PER_EPOCH = NUM_TRAINING_IMAGES // BATCH_SIZE
X_train, X_valid, y_train, y_valid = model_selection.train_test_split(X, y, test_size=0.2)
 X_train.shape, X_valid.shape, y_train.shape, y_valid.shape<data_type_conversions>
history = model.fit(
 get_training_dataset() ,
epochs=EPOCHS,
callbacks=[lr_schedule],
steps_per_epoch=STEPS_PER_EPOCH
)
class DatasetRetriever(Dataset):
def __init__(self, X, y, transforms=None):
super().__init__()
self.X = X.reshape(-1, 28, 28 ).astype(np.float32)
 self.y = y
self.transforms = transforms
def __getitem__(self, index):
image, target = self.X[index], self.y[index]
image = np.stack([image] * 3, axis=-1)
 image /= 255.
 if self.transforms:
image = self.transforms(image=image)['image']
return image, torch.tensor(target, dtype=torch.long)
 def __len__(self):
return self.y.shape[0]<feature_engineering>
test_ds = get_test_dataset(ordered=True)
 print('Computing predictions...')
 test_images_ds = test_ds.map(lambda image, idnum: image)
 probabilities = model.predict(test_images_ds)
def get_train_transforms() :
return A.Compose(
 [
A.Rotate(limit=10, border_mode=cv2.BORDER_REPLICATE, p=0.5),
A.Cutout(num_holes=8, max_h_size=2, max_w_size=2, fill_value=0, p=0.5),
A.Cutout(num_holes=8, max_h_size=1, max_w_size=1, fill_value=1, p=0.5),
A.Resize(32, 32, p=1.) ,
ToTensorV2(p=1.0),
],
p=1.0)
 def get_valid_transforms() :
return A.Compose(
 [
A.Resize(32, 32, p=1.) ,
ToTensorV2(p=1.0),
],
p=1.0
)<prepare_x_and_y>
sub1 = sub.copy()
sub2 = sub.copy()
train_dataset = DatasetRetriever(
 X = X_train,
y = y_train,
transforms=get_train_transforms() , 
)
 valid_dataset = DatasetRetriever(
 X = X_valid,
y = y_valid,
transforms=get_valid_transforms() ,
)<load_pretrained>
print('Generating submission.csv file...')
 test_ids_ds = test_ds.map(lambda image, idnum: idnum ).unbatch()
test_ids = next(iter(test_ids_ds.batch(NUM_TEST_IMAGES)) ).numpy().astype('U' )
train_loader = DataLoader(
 train_dataset,
batch_size=DataLoaderConfig.batch_size,
shuffle=True,
num_workers=DataLoaderConfig.num_workers, 
)
 valid_loader = DataLoader(
 valid_dataset,
batch_size=DataLoaderConfig.batch_size,
shuffle=False,
num_workers=DataLoaderConfig.num_workers,
)<init_hyperparams>
pred_df = pd.DataFrame({'image_name': test_ids, 'target': np.concatenate(probabilities)})
 pred_df.head()
class LossMeter:
def __init__(self):
self.avg = 0
self.sum = 0
self.count = 0
def update(self, val, n=1):
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
class AccMeter:
def __init__(self):
self.true_count = 0
self.all_count = 0
self.avg = 0
def update(self, y_true, y_pred):
y_true = y_true.cpu().numpy().astype(int)
 y_pred = y_pred.cpu().numpy().argmax(axis=1 ).astype(int)
 self.true_count +=(y_true == y_pred ).sum()
self.all_count += y_true.shape[0]
self.avg = self.true_count / self.all_count<choose_model_class>
sub4 = pd.read_csv('/kaggle/input/submissionb7/submissionB7-2.csv' )
class Fitter:
def __init__(
 self, model, device, criterion, n_epochs,
lr, sheduler=None, scheduler_params=None 
):
self.epoch = 0
self.n_epochs = n_epochs
self.base_dir = './'
self.log_path = f'{self.base_dir}/log.txt'
self.best_summary_loss = np.inf
self.model = model
self.device = device
self.optimizer = torch.optim.Adam(self.model.parameters() , lr=lr)
 if sheduler:
self.scheduler = sheduler(self.optimizer, **scheduler_params)
 self.criterion = criterion().to(self.device)
 self.log(f'Fitter prepared.Device is {self.device}')
 def fit(self, train_loader, valid_loader):
for e in range(self.n_epochs):
current_lr = self.optimizer.param_groups[0]['lr']
self.log(f'
{datetime.datetime.utcnow().isoformat() }
LR: {current_lr}')
 t = int(time.time())
 summary_loss, final_scores = self.train_one_epoch(train_loader)
 self.log(
 f'[RESULT]: Train.Epoch: {self.epoch}, ' + \
f'summary_loss: {summary_loss.avg:.5f}, ' + \
f'final_score: {final_scores.avg:.5f}, ' + \
f'time: {int(time.time())- t} s' 
)
 t = int(time.time())
 summary_loss, final_scores = self.validation(valid_loader)
 self.log(
 f'[RESULT]: Valid.Epoch: {self.epoch}, ' + \
f'summary_loss: {summary_loss.avg:.5f}, ' + \
f'final_score: {final_scores.avg:.5f}, ' + \
f'time: {int(time.time())- t} s' 
)
 f_best = 0
if summary_loss.avg < self.best_summary_loss:
self.best_summary_loss = summary_loss.avg
f_best = 1
self.scheduler.step(metrics=summary_loss.avg)
 self.save(f'{self.base_dir}/last-checkpoint.bin')
 if f_best:
self.save(f'{self.base_dir}/best-checkpoint.bin')
 print('New best checkpoint')
 self.epoch += 1
def validation(self, val_loader):
self.model.eval()
summary_loss = LossMeter()
final_scores = AccMeter()
t = int(time.time())
 for step,(images, targets)in enumerate(val_loader):
print(
 f'Valid Step {step}/{len(val_loader)}, ' + \
f'summary_loss: {summary_loss.avg:.5f}, ' + \
f'final_score: {final_scores.avg:.5f}, ' + \
f'time: {int(time.time())- t} s', end='\r' 
)
 with torch.no_grad() :
targets = targets.to(self.device)
 images = images.to(self.device)
 batch_size = images.shape[0]
outputs = self.model(images)
 loss = self.criterion(outputs, targets)
 final_scores.update(targets, outputs)
 summary_loss.update(loss.detach().item() , batch_size)
 return summary_loss, final_scores
def train_one_epoch(self, train_loader):
self.model.train()
summary_loss = LossMeter()
final_scores = AccMeter()
t = int(time.time())
 for step,(images, targets)in enumerate(train_loader):
print(
 f'Train Step {step}/{len(train_loader)}, ' + \
f'summary_loss: {summary_loss.avg:.5f}, ' + \
f'final_score: {final_scores.avg:.5f}, ' + \
f'time: {int(time.time())- t} s', end='\r' 
)
 targets = targets.to(self.device)
 images = images.to(self.device)
 batch_size = images.shape[0]
self.optimizer.zero_grad()
outputs = self.model(images)
 loss = self.criterion(outputs, targets)
 loss.backward()
final_scores.update(targets, outputs.detach())
 summary_loss.update(loss.detach().item() , batch_size)
 self.optimizer.step()
return summary_loss, final_scores
def save(self, path):
self.model.eval()
torch.save({
'model_state_dict': self.model.state_dict() ,
'optimizer_state_dict': self.optimizer.state_dict() ,
'scheduler_state_dict': self.scheduler.state_dict() ,
'best_summary_loss': self.best_summary_loss,
'epoch': self.epoch,
}, path)
 def load(self, path):
checkpoint = torch.load(path)
 self.model.load_state_dict(checkpoint['model_state_dict'])
 self.optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
 self.scheduler.load_state_dict(checkpoint['scheduler_state_dict'])
 self.best_summary_loss = checkpoint['best_summary_loss']
self.epoch = checkpoint['epoch'] + 1
def log(self, message):
print(message)
 with open(self.log_path, 'a+')as logger:
logger.write(f'{message}
' )<choose_model_class>
sub5 = pd.read_csv('/kaggle/input/submissionb3/submissionB3.csv' )
def get_net() :
net = efficientnet_pytorch.EfficientNet.from_pretrained('efficientnet-b7')
 net._fc = nn.Linear(in_features=2560, out_features=10, bias=True)
 return net
net = get_net().to(DEVICE )<choose_model_class>
del sub1['target']
sub1 = sub1.merge(pred_df, on='image_name')
 sub1.head()
fitter = Fitter(
 model=net,
device=DEVICE,
criterion=TrainConfig.criterion,
n_epochs=TrainConfig.n_epochs,
lr=TrainConfig.lr,
sheduler=TrainConfig.scheduler,
scheduler_params=TrainConfig.scheduler_params
)<train_model>
sub1.to_csv('submission-B5.csv',index=False )
fitter.fit(train_loader, valid_loader )<load_pretrained>
sub3 = pd.read_csv('/kaggle/input/subeffnetb0/submissionB0.csv' )
<load_from_csv><EOS> 
model.save('EffNetB5-Melanoma.h5')