Kaggle competition: RANZCR CLiP - Catheter and Line Position Challenge
<SOS> metric: MCAUC Kaggle data source: ranzcr-clip-catheter-and-line-position-challenge<data_type_conversions>
tez_path = '.. /input/tez-lib/'
effnet_path = '.. /input/efficientnet-pytorch/'
sys.path.append(tez_path)
 sys.path.append(effnet_path )
test_data['Date'] = pd.to_numeric(test_data['Date'] )<define_variables>
import os
import albumentations
import pandas as pd
import numpy as np
import tez
from tez.datasets import ImageDataset
import torch
import torch.nn as nn
from torch.nn import functional as F
from efficientnet_pytorch import EfficientNet
columnst = [c for c in columnst if c not in ['ForecastId', 'Province/State', 'Country/Region']]
columnst<predict_on_test>
INPUT_PATH = ".. /input/ranzcr-clip-catheter-line-classification/"
IMAGE_PATH = ".. /input/ranzcr-clip-catheter-line-classification/test/"
MODEL_PATH = ".. /input/ranzcr-effnet5/"
IMAGE_SIZE = 512
y1_pred = regressor.predict(test_data[columnst] )<train_model>
df = pd.read_csv(os.path.join(INPUT_PATH, "sample_submission.csv"))
regressor.fit(X_train,Y2_train)
<predict_on_test>
class RanzcrModel(tez.Model):
def __init__(self):
super().__init__()
self.effnet = EfficientNet.from_name("efficientnet-b5")
 self.effnet._conv_stem.in_channels = 1
weight = self.effnet._conv_stem.weight.mean(1, keepdim=True)
 self.effnet._conv_stem.weight = torch.nn.Parameter(weight)
 self.dropout = nn.Dropout(0.1)
 self.out = nn.Linear(2048, 11)
 def forward(self, image, targets=None):
batch_size, _, _, _ = image.shape
x = self.effnet.extract_features(image)
 x = F.adaptive_avg_pool2d(x, 1 ).reshape(batch_size, -1)
 outputs = self.out(self.dropout(x))
return outputs, None, {}
y2_pred = regressor.predict(test_data[columnst] )<load_from_csv>
test_aug = albumentations.Compose(
 [
albumentations.Resize(IMAGE_SIZE, IMAGE_SIZE, p=1.0),
albumentations.HorizontalFlip(p=0.5),
albumentations.Normalize(
 mean=[0.485],
std=[0.229],
max_pixel_value=255.0,
p=1.0, 
),
],
p=1.0,
)
pred1 = pd.DataFrame(y1_pred)
 pred2 = pd.DataFrame(y2_pred)
 sub_df = pd.read_csv('.. /input/covid19-global-forecasting-week-1/submission.csv')
 sub_df.head()<save_to_csv>
test_image_paths = [
os.path.join(IMAGE_PATH, x + ".jpg")
 for x in df.StudyInstanceUID.values
]
datasets = pd.concat([sub_df['ForecastId'],pred1,pred2],axis=1)
 datasets.columns = ['ForecastId','ConfirmedCases','Fatalities']
datasets.to_csv('submission.csv',index=False )<load_from_csv>
model = RanzcrModel()
model.load(os.path.join(MODEL_PATH, "effnet5_fold_0.bin"))
train_data = pd.read_csv("/kaggle/input/titanic/train.csv")
 train_data.head(n=10)
<load_from_csv>
final_preds = None
for j in range(2):
test_dataset = ImageDataset(
 image_paths=test_image_paths,
targets=[0]*len(test_image_paths),
augmentations=test_aug,
grayscale=True, 
)
 preds = model.predict(test_dataset, batch_size=32, n_jobs=-1, device="cuda")
 temp_preds = None
for p in preds:
if temp_preds is None:
temp_preds = p
else:
temp_preds = np.vstack(( temp_preds, p))
if final_preds is None:
final_preds = temp_preds
else:
final_preds += temp_preds
final_preds /= 2
test_data = pd.read_csv("/kaggle/input/titanic/test.csv")
 test_data.describe()<filter>
target_cols = df.columns[1:]
for i in range(final_preds.shape[1]):
df.loc[:, target_cols[i]] = final_preds[:, i]
<create_dataframe><EOS> 
df.to_csv('submission.csv', index=False)
 df.head()