Kaggle competition: Open Images 2019 - Object Detection
package_dir = ".. /input/pretrained-models/pretrained-models/pretrained-models.pytorch-master/"
sys.path.insert(0, package_dir)
 device = torch.device("cuda:0")
 ImageFile.LOAD_TRUNCATED_IMAGES = True<load_from_csv>
base_dir='.. /input/'
df1=pd.read_csv(base_dir+'tf-hub-end/'+'submission_75k.csv')
 df1.head()
class RetinopathyDatasetTest(Dataset):
def __init__(self, csv_file, transform):
self.data = pd.read_csv(csv_file)
 self.transform = transform
def __len__(self):
return len(self.data)
 def __getitem__(self, idx):
img_name = os.path.join('.. /input/aptos2019-blindness-detection/test_images', self.data.loc[idx, 'id_code'] + '.png')
 image = Image.open(img_name)
 image = self.transform(image)
 return {'image': image}<choose_model_class>
base_dir='.. /input/'
df2=pd.read_csv(base_dir+'tf-hub-75k/'+'submission_75k.csv')
 df2.head()
model = pretrainedmodels.__dict__['resnet101'](pretrained=None)
 model.avg_pool = nn.AdaptiveAvgPool2d(1)
 model.last_linear = nn.Sequential(
 nn.BatchNorm1d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True),
nn.Dropout(p=0.25),
nn.Linear(in_features=2048, out_features=2048, bias=True),
nn.ReLU() ,
nn.BatchNorm1d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True),
nn.Dropout(p=0.5),
nn.Linear(in_features=2048, out_features=1, bias=True), 
)
 model.load_state_dict(torch.load(".. /input/mmmodel/model.bin"))
model = model.to(device )<find_best_params>
base_dir='.. /input/'
df3=pd.read_csv(base_dir+'tf-hub-25-to-50-k/'+'submission_50k.csv')
 df3.head()
for param in model.parameters() :
param.requires_grad = False
model.eval()<load_from_csv>
base_dir='.. /input/'
df4=pd.read_csv(base_dir+'tf-hub/'+'submission_25k.csv')
 df4.head()
test_transform = transforms.Compose([
transforms.Resize(( 224, 224)) ,
transforms.RandomHorizontalFlip() ,
transforms.ToTensor() ,
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
 ])
 test_dataset = RetinopathyDatasetTest(csv_file='.. /input/aptos2019-blindness-detection/sample_submission.csv',
transform=test_transform )<predict_on_test>
df_final=pd.concat([df1, df2, df3, df4])
 df_final.head()
<predict_on_test><EOS> 
df_final.to_csv('submission.csv',index=None )