{"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":"code","source":"# Wandb for logging all the training info\n\nimport wandb\n\ntry:\n    from kaggle_secrets import UserSecretsClient\n    user_secrets = UserSecretsClient()\n    api_key = user_secrets.get_secret(\"wandb_key\")\n    wandb.login(key=api_key)\n    anony = None\nexcept:\n    anony = \"must\"\n    print('If you want to use your W&B account, go to Add-ons -> Secrets and provide your W&B access token. Use the Label name as wandb_api. \\nGet your W&B access token from here: https://wandb.ai/authorize')","metadata":{"execution":{"iopub.status.busy":"2022-03-14T10:28:06.527616Z","iopub.execute_input":"2022-03-14T10:28:06.528142Z","iopub.status.idle":"2022-03-14T10:28:09.101397Z","shell.execute_reply.started":"2022-03-14T10:28:06.528097Z","shell.execute_reply":"2022-03-14T10:28:09.100343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Backbone models library\n! pip install timm","metadata":{"execution":{"iopub.status.busy":"2022-03-14T10:28:09.103047Z","iopub.execute_input":"2022-03-14T10:28:09.103303Z","iopub.status.idle":"2022-03-14T10:28:21.454215Z","shell.execute_reply.started":"2022-03-14T10:28:09.103263Z","shell.execute_reply":"2022-03-14T10:28:21.453143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Training configurations\n\nimport yaml\n\ndata = {\n    # Other configs\n    'root_dir': '../input/happy-whale-and-dolphin',\n    'save_dir': '',\n    'title_run': 'baseline',\n    'save_last_model': True,\n    'load_model': False,\n    'wandb_logging': True,\n    'n_fold': 6,\n    'fold': 1,\n\n    # Model related hyperparameters\n    'model_name': \"tf_efficientnet_b0_ns\",\n    'n_epochs': 3,\n    'img_size': 448,\n    'num_classes': 15587,\n    'embedding_size': 512,\n    'train_batch_size': 32,\n    'val_batch_size': 4,\n    'lr': 1e-4,\n    'device': \"cuda:0\",\n    'num_workers': 2,\n\n    # ArcFace hyperparameters\n    's': 30.0,\n    'm': 0.50,\n    'ls_eps': 0.0,\n    'easy_margin': False,\n    \n    # Inference hyperparameters\n    'num_neighbors': 10,\n    'test_batch_size': 32,\n    'pred_model_path': '../input/model-weights/baseline_best_model_weights.pt',\n}\n\n# Save config as file\nwith open('config.yaml', 'w') as outfile:\n    yaml.dump(data, outfile, default_flow_style=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-14T10:28:21.458524Z","iopub.execute_input":"2022-03-14T10:28:21.459263Z","iopub.status.idle":"2022-03-14T10:28:21.472511Z","shell.execute_reply.started":"2022-03-14T10:28:21.459227Z","shell.execute_reply":"2022-03-14T10:28:21.471354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Run this cell to process dataframe for training\n# It encodes labels and saves label encoder\nimport sys\nsys.path.insert(1, '../input/train-files')\nfrom utils import preprocess_train_dataframe\n\npreprocess_train_dataframe()","metadata":{"_uuid":"2b61dbbc-8a5c-4754-a05f-32940c33c018","_cell_guid":"17564c09-80b2-443e-bbcc-26b85eeee5a5","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2022-03-14T10:28:21.475134Z","iopub.execute_input":"2022-03-14T10:28:21.476041Z","iopub.status.idle":"2022-03-14T10:28:25.935357Z","shell.execute_reply.started":"2022-03-14T10:28:21.475952Z","shell.execute_reply":"2022-03-14T10:28:25.934367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Run the training code\n!python ../input/train-files/train_baseline.py -p config.yaml","metadata":{"execution":{"iopub.status.busy":"2022-03-13T04:15:28.006985Z","iopub.execute_input":"2022-03-13T04:15:28.007463Z","iopub.status.idle":"2022-03-13T07:09:36.089985Z","shell.execute_reply.started":"2022-03-13T04:15:28.007426Z","shell.execute_reply":"2022-03-13T07:09:36.089052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Inference","metadata":{}},{"cell_type":"code","source":"from utils import process_test_dataframe\n\nprocess_test_dataframe()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T10:28:28.10209Z","iopub.execute_input":"2022-03-14T10:28:28.102741Z","iopub.status.idle":"2022-03-14T10:28:28.369916Z","shell.execute_reply.started":"2022-03-14T10:28:28.102703Z","shell.execute_reply":"2022-03-14T10:28:28.368883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Run the inference code\n!python ../input/train-files/predict.py -p config.yaml","metadata":{"execution":{"iopub.status.busy":"2022-03-14T10:28:29.358949Z","iopub.execute_input":"2022-03-14T10:28:29.359649Z","iopub.status.idle":"2022-03-14T15:05:28.665696Z","shell.execute_reply.started":"2022-03-14T10:28:29.359601Z","shell.execute_reply":"2022-03-14T15:05:28.664513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"while True:\n    continue","metadata":{"execution":{"iopub.status.busy":"2022-03-14T15:05:28.668244Z","iopub.execute_input":"2022-03-14T15:05:28.669834Z","iopub.status.idle":"2022-03-14T15:39:14.382837Z","shell.execute_reply.started":"2022-03-14T15:05:28.669779Z","shell.execute_reply":"2022-03-14T15:39:14.381192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}