Skip to content

Instantly share code, notes, and snippets.

@Borda
Created September 13, 2021 12:04
Show Gist options
  • Select an option

  • Save Borda/4bf6e0cfa84a973b0f3ea595839ef241 to your computer and use it in GitHub Desktop.

Select an option

Save Borda/4bf6e0cfa84a973b0f3ea595839ef241 to your computer and use it in GitHub Desktop.
Simple Submitting Kernel to Kaggle Competition
preds = []
# move model to GPU for faster inference and set evaluation
model.cuda().eval()
for imgs, names in dm.test_dataloader():
# for the prediction we do not need gradients
with torch.no_grad():
onehots = model(imgs.cuda()).cpu()
# aggregate particular preditions
for oh, name in zip(onehots, names):
lbs = dm.onehot_to_labels(oh)
preds.append(dict(image=name, labels=" ".join(lbs[::-1])))
df_preds = pd.DataFrame(preds)
# show sample predictions
print(df_preds.head())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment