{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"<a id=\"\"><font color='#425066'><h2>Introduction</h2></font></a>\n\nThis two part kernel showcases how to properly finetune a ConvNext Base model on [130k Images (512x512) - Universal Image Embeddings\n](https://www.kaggle.com/datasets/rhtsingh/130k-images-512x512-universal-image-embeddings) dataset and do submission. The inference kernel is available here [Google Universal Image Embedding - ConvNext Infer\n](https://www.kaggle.com/code/rhtsingh/google-universal-image-embedding-convnext-infer).\n\nInstead of putting everything in one notebook, I have created scripts which makes things more manageable and is available here [universal_image_embedding_src\n](https://www.kaggle.com/datasets/rhtsingh/universal-image-embedding-sourcecode). The scripts act as a placeholder for better understanding of how to finetune. It also contains useful techniques and code snippets that one can easy plug and play in their code. \n\nI myself had issues at various stages and these kernel is to for those who are new or are still trying to figure out. \n\n*Note: By now we have figured that the pretrained model itself performs better than the finetuned one for some very weird reasons and same goes for this kernel. I am really excited to see where this competition goes.*\n\n\n<a id=\"\"><font color='#425066'><h3>Install Timm</h3></font></a>\n\nWe will be using timm for downloading pretrained models which we first need to install since its not available in Kaggle environment.\n","metadata":{}},{"cell_type":"code","source":"!pip -q install timm","metadata":{"execution":{"iopub.status.busy":"2022-08-02T08:29:20.964007Z","iopub.execute_input":"2022-08-02T08:29:20.964533Z","iopub.status.idle":"2022-08-02T08:29:37.284137Z","shell.execute_reply.started":"2022-08-02T08:29:20.964439Z","shell.execute_reply":"2022-08-02T08:29:37.282469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"\"><font color='#425066'><h3>Run</h3></font></a>\n\nTo run we will simply call `main.py` and pass all the necessary arguments. Here I am training only for 1 epoch, do make sure to change that. \n\nMy best finetuned model acheived `F1 score of 91.65` and `Accuracy score of 96.37` with `LB score of 0.354`.","metadata":{}},{"cell_type":"code","source":"!python ../input/universal-image-embedding-sourcecode/main.py \\\n--project=\"runs\" \\\n--data_path=\"../input/130k-images-512x512-universal-image-embeddings/\" \\\n--half_precision_backend=\"cuda_amp\" \\\n--train_batch_size=64 \\\n--validation_batch_size=128 \\\n--image_size=384 \\\n--num_epochs=1","metadata":{"execution":{"iopub.status.busy":"2022-08-02T08:34:24.494438Z","iopub.execute_input":"2022-08-02T08:34:24.496037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"\"><font color='#425066'><h3>Thanks, Do Upvote!</h3></font></a>\n\nLet me know in the comments section for any doubts.","metadata":{}}]}