Loading

FOODCH

Getting Started Notebook for FOODCH

A getting started notebook with random submission for the challenge.

ashivani

Getting Started Notebook for FOODCH Challenge

This notebook creates a random prediction for the test data and takes you through the workflow of how to download data and submit directly via the notebook.

Note: Create a copy of the notebook and use the copy for submission. Go to File > Save a Copy in Drive to create a new copy

Download the files 💾

Downlad AIcrowd CLI

We will first install aicrowd-cli which will help you download and later make submission directly via the notebook.

In [ ]:
!pip install aicrowd-cli
%load_ext aicrowd.magic
Requirement already satisfied: aicrowd-cli in /usr/local/lib/python3.7/dist-packages (0.1.10)
Requirement already satisfied: toml<1,>=0.10.2 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (0.10.2)
Requirement already satisfied: requests<3,>=2.25.1 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (2.26.0)
Requirement already satisfied: requests-toolbelt<1,>=0.9.1 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (0.9.1)
Requirement already satisfied: click<8,>=7.1.2 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (7.1.2)
Requirement already satisfied: pyzmq==22.1.0 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (22.1.0)
Requirement already satisfied: rich<11,>=10.0.0 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (10.13.0)
Requirement already satisfied: GitPython==3.1.18 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (3.1.18)
Requirement already satisfied: tqdm<5,>=4.56.0 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (4.62.3)
Requirement already satisfied: typing-extensions>=3.7.4.0 in /usr/local/lib/python3.7/dist-packages (from GitPython==3.1.18->aicrowd-cli) (3.10.0.2)
Requirement already satisfied: gitdb<5,>=4.0.1 in /usr/local/lib/python3.7/dist-packages (from GitPython==3.1.18->aicrowd-cli) (4.0.9)
Requirement already satisfied: smmap<6,>=3.0.1 in /usr/local/lib/python3.7/dist-packages (from gitdb<5,>=4.0.1->GitPython==3.1.18->aicrowd-cli) (5.0.0)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (1.24.3)
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (2.0.7)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (2021.10.8)
Requirement already satisfied: colorama<0.5.0,>=0.4.0 in /usr/local/lib/python3.7/dist-packages (from rich<11,>=10.0.0->aicrowd-cli) (0.4.4)
Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in /usr/local/lib/python3.7/dist-packages (from rich<11,>=10.0.0->aicrowd-cli) (0.9.1)
Requirement already satisfied: pygments<3.0.0,>=2.6.0 in /usr/local/lib/python3.7/dist-packages (from rich<11,>=10.0.0->aicrowd-cli) (2.6.1)

Login to AIcrowd ㊗

In [ ]:
%aicrowd login
Please login here: https://api.aicrowd.com/auth/YOsusECHq6i33LHsqjV0EarFe-bPQmIYwXs7-yq8Bx4
API Key valid
Saved API Key successfully!

Download Dataset and Unzip

We will create a folder name data and download and unzip the files there.

In [ ]:
# Downloading the Dataset
!rm -rf data
!mkdir data
%aicrowd ds dl -c foodch -o data
Error in downloading dataset https://datasets.aicrowd.com/default/aicrowd-practice-challenges/public/foodc/v0.1/test.csv
In [ ]:
!unzip data/train_images -d data/train_images > /dev/null
!unzip data/test_images -d data/test_images > /dev/null

Generating Random Submission ⚙️

Making a submission with random predictions. We will randomly select a class prensent in the training set for each image in test set.

In [ ]:
# Imporitng libraries
import pandas as pd
import os
import random

random.seed(42)
In [ ]:
# Testing images directory

test_images_dir = os.path.join("data", "test_images", "test_images")
test_name_ids = os.listdir(test_images_dir)
In [ ]:
# Making a list containing all unique classes in the training set

# Reading the training dataset
training_dataframe = pd.read_csv(os.path.join("data", "train.csv"))

# Classes column
classes = training_dataframe['ClassName'].unique()

# Creating a list containing random classes of size equal of no. of samples in test data
random_test_predictions = [random.choice(classes) for i in range(len(test_name_ids))]
In [ ]:
# Converting the list to dataframe

predictions_df = pd.DataFrame(random_test_predictions, columns=["ClassName"])
predictions_df
Out[ ]:
ClassName
0 leaf-spinach
1 apple
2 pizza-margherita-baked
3 chicken
4 zucchini
... ...
479 soft-cheese
480 onion
481 egg
482 water
483 tomato

484 rows × 1 columns

In [ ]:
# Saving the dataframe to csv
predictions_df.to_csv("submission.csv", index=False)

Submitting the predictions to AIcrowd

In [ ]:
# Submitting the Predictions

!aicrowd submission create -c foodch -f submission.csv
submission.csv ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0%7.3/5.7 KB?0:00:00
Submission Upload Error: Couldn't decode response from AIcrowd servers
In [ ]:


Comments

You must login before you can post a comment.

Execute