A spaghetti workspace that deals with different hugging face models. It was started to execute supervised fine tuning of CLIP model of different sizes. But after few iterations I realized that these models are not trained on a large amount of non western visual input. I tried to train them but this resulted in overfitting.
So then I wrote a code that would use a model pipeline. First it would separate objects using grounding-dino, then these objects were separated using ffmpeg. :) and the CLIP was run. Still there was no significant success.
A permissible inference would
- Not reject any image that has musical instruments and hence music making.
- If it cant determine whether image has music making, it will pass the image as music making.
The rationale is that it is ok to wrongly categorize something as music making but the model should not skip any image that has a slight indication (In any manner) of music making.
Next things to try would be
- Run clip and then openAI
- Run grounding-dino, clip and openAI.
These are yet tobe done as of on 22nd Oct 2026.
- Data for different museums will be organized into different csvs. Currently we are processing 2.
a. Cleveland museum of art (museumid=cma)
b. Metropolitan museum of art (museumid=met)
2.There might be errors, some uninitialized fields necessary for the bookkeeping for the training. So these datafiles are first normalized and merged into a single file. The command for this is
python -m datasets.normalize_data. This generatesdatasets/csvs/training/normalized_output.csv - Once the data is normalized the process is not repeated unless there is a new museum for which the model needs a training.
- To prepare the training data from normalized data, code first finds out the image url by calling the museum's objet endpoint. ObjectId from the normalized data is used for fetching the collection-object information. This results into a training file
datasets/csvs/training/intermediate/training_source.csv. It has following columnsimage_url,title,museum_index,id,instruments. - Here
instrumentsis a list of the instruments present in the current paintings. Usually single painting contains multiple instrument and this is crucial to keep in mind. - Training file is not generated every time. It is generated only if the file is not present on the path
datasets/csvs/training/intermediate/training_source.csv - The training file is then loaded into memory as a dataframe and for every instrument, this dataframe is divided into 2 sets. One is training set and other is validation set.
- Training set contains 80% of the total instances and a validation set contains 20% of the total instances for a particular instrument. In other words, if the dataset has 10 pakhawaj depictions, 8 will be used in training and 2 will be used in validation.
- It is important to keep in mind that images may get downloaded multiple times in the first run. This is because a single image contains multiple instruments. So it will get downloaded for that particular instruments' training set.
- Assuming that the first run was successful and it downloaded all the images for the consecuitive runs, it only checks if the file is present on the path.
- Another important aspect is how the data is divided between training and validation. It is important to note that an image in context of a instrument can not be present in both training and validation set. i.e image['i1']['objectid1'] can not exist simultaniously in the training and validation set for instrument i1. But it could exist for the instrument i2.
python3 -m venv training
source training/bin/activate
pip install -r requirements.txtRun either of the 4 commands:
python -m src.run training
python -m src.run inference
python -m src.run quick-training
python -m src.run quick-inferenceRunning python -m src.run training prepares everything from scratch:
- From
datasets/csvs/training/knowledge_basecreates a normalized dataset. - From
datasets/csvs/training/normalized_output.csvpreparesdatasets/csvs/training/intermediate/training_source.csvwith the following columns:image_url,title,museum_index,id,instruments. Whenever the museum exposes APIs, these APIs are used for getting image_url and other information. - Using
datasets/csvs/training/intermediate/training_source.csv, prepares necessary directory structure and downloads files if required. - Makes the final objects file (datasets/csvs/training/training_objects.csv and datasets/csvs/training/validation_objects.csv) used in training. This contains
(id, instrument, museum_index, local_path). - Runs the training loop
- Stores the adjusted matrix in output as clip_finetuned.pt
Running python -m src.run quick-training assumes that files are available.
- Does not download anything except running training loop on the final object files.
- Assumes that datasets/csvs/training/training_objects.csv and datasets/csvs/training/validation_objects.csv are available.
- Stores the adjusted matrix in output as clip_finetuned.pt
Running python -m src.run inference prepares everything from scratch:
- From
datasets/csvs/inference/knowledge_basecreates a normalized dataset. - From
datasets/csvs/inference/normalized_output.csvpreparesdatasets/csvs/inference/intermediate/inference_sources.csvwith the following columns:image_url,title,museum_index,id,instruments. Whenever the museum exposes APIs, these APIs are used for getting image_url and other information. - Using
datasets/csvs/inference/intermediate/inference_sources.csv, prepares necessary directory structure and downloads files if required. - Makes the final objects file (datasets/csvs/inference/inference_objects.csv) used in training. This contains
(id, instrument, museum_index, local_path). - Runs the inference loop
- Prepares output/probabilities.csv
Running python -m src.run quick-inference assumes that files are available.
- Does not download anything except running inference loop on the final object files.
- Assumes that datasets/csvs/inference/inference_objects.csv is available.
- Prepares output/probabilities.csv