# Image Classification with Weak Labels

*English translation by SOTA – AI Community of the Georgian original. Organisers who would like this translation removed can email sota.ai.community@gmail.com.*

*Source: the Final Round of the Georgian National AI Olympiad, organised by the Georgian Artificial Intelligence Association (GAIA), 25 May 2025, hosted on the Bohrium platform: [original statement](https://www.bohrium.com/competitions/6576265377). The statement file on Bohrium is named `e_en.md`, but its text is in Georgian.*

## 📷 Task: Image Classification Using Weak Labels


## 🧠 Story

You are taking part in an international programme that aims to classify large-scale visual data from countries where full annotation of the data is impossible in terms of cost and time.

As part of the project, thousands of photos of everyday scenes are being collected — animals, transport, plants and people. However, only a small share of these photos has a detailed description, while most have remained without annotations.

Your assignment in the AI research group is to **determine the probable classes using only the text descriptions** (weak labels), and then to train your own **image classification model from scratch** on these data, so that unknown images can be classified automatically.


---


## 🎯 Your mission

You will be provided with a dataset split into two parts:

- **`captions.csv` data**: image paths accompanied by text descriptions (for example, `"A dog jumping over a rock in a grassy field"`), but not by direct labels.
- **`test_imgs.csv` data**: images that have neither descriptions nor labels. Your model must predict the correct class for them.

Your goal is to:
1. use the descriptions to **obtain weak labels** — i.e. smart guesses of the class derived from the text.
2. build and train from scratch an **image classification model** that can determine the correct class from the image.
3. use this model to make predictions on the test images and compile the final predictions file.


---


## ⚙️ Technical constraints

- The classification covers **8 classes** — from a natural image dataset: `[airplane, car, cat, dog, flower, fruit, motorbike, person]`
- Your solution **must run on a T4 GPU within at most 1 hour**
- **Each image is 128x128 in size (RGB colour)**.
- **The notebook will be evaluated in full after pressing the `Run all` button** — the code must not require manual running or any step-by-step intervention.
- The final predictions file must be created automatically at the end of the notebook, with the name **`submission.json`**
- **Using external models is forbidden**: models may not be downloaded from Hugging Face or other sources.
- **Pre-trained image classifiers may not be used**, including CLIP, ViT, ResNet, etc.
- Only generating weak labels from the text is allowed.


---


## 📦 Deliverables

Your submission will be evaluated by accuracy.

You must submit:

1. A **Jupyter Notebook** that:
  - obtains weak labels from the text descriptions
  - trains a new classifier from scratch
  - makes predictions on the test images
  - creates the `submission.json` file automatically at the end of the notebook

2. A **`submission.json`** file in the following format:
```json
{
 "image_001.jpg": "cat",
 "image_002.jpg": "motorbike",
}
```


## Starter code
Below are the instructions for loading the initial data and creating the final output. In the last part, please change only the part where you store the answers in the Dict; do not change the saving step, and above all do not change the file name, otherwise you will receive 0 points.


```python
import pandas as pd

# Note that here you must insert the path that you will see in the Bohrium notebook
captions = pd.read_csv("captions.csv")
captions

# Note that here you must insert the path that you will see in the Bohrium notebook
test = pd.read_csv("test_imgs.csv")
test


# Your code
# ..
# ..








import json

# You may also change the parameters of this function; the main thing is that at the end you #create submission.json following the approach written here
def create_predictions_json(test_data):
   """
   Creates submission.json file. Currently outputs 'cat' for all students.
   TODO: Replace hardcoded 'cat' with actual model predictions.
   Do not modify the JSON saving part at the end.
   """
   predictions = {}
   for path in test_data:
       # TODO: add prediction logic here using your model.
       final_prediction = "cat"  # Replace with actual prediction


       predictions[path[path.index("test_imgs"):]] = final_prediction

   # DO NOT MODIFY
   with open('submission.json', 'w') as f:
       json.dump(predictions, f, indent=4)


   print(f"Predictions saved to submission.json with {len(predictions)} entries")


test_path_list = test['path'].tolist()
create_predictions_json(test_path_list)

```
