{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "image_classification(vit)", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "4cb12c6ecab94ebd8f3fadaa8bfd685c": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_7d17331c93574d66aa925e74cdedc39f", "IPY_MODEL_3e327e2400484ee09de4965619bade63", "IPY_MODEL_e5735a606c5b4fd0b602c2089af48e1e" ], "layout": "IPY_MODEL_389538ce930d4e8699d7b7c529b5cada" } }, "7d17331c93574d66aa925e74cdedc39f": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_9bfda416531d42f3b17465a332dd3464", "placeholder": "", "style": "IPY_MODEL_56032978d04b4f449f08e1b917d9e87a", "value": "100%" } }, "3e327e2400484ee09de4965619bade63": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_49237dfae42d46199ef12c74ba83029b", "max": 3, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_2d9131122ac34b019309bc2b0a9fd09f", "value": 3 } }, "e5735a606c5b4fd0b602c2089af48e1e": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_c706a8841f724ffc897e35ac8408b5b1", "placeholder": "", "style": "IPY_MODEL_bc488d9d60384eefbdc9fc794f0dfdd8", "value": " 3/3 [00:00<00:00, 63.97it/s]" } }, "389538ce930d4e8699d7b7c529b5cada": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "9bfda416531d42f3b17465a332dd3464": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "56032978d04b4f449f08e1b917d9e87a": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "49237dfae42d46199ef12c74ba83029b": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "2d9131122ac34b019309bc2b0a9fd09f": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "c706a8841f724ffc897e35ac8408b5b1": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "bc488d9d60384eefbdc9fc794f0dfdd8": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "ca7c3a5fba644a508f786cf5c5a7999a": { "model_module": "@jupyter-widgets/controls", "model_name": "VBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "VBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "VBoxView", "box_style": "", "children": [ "IPY_MODEL_facf2022580948299453af6b562fe1c4", "IPY_MODEL_4d40c583c368402fbc3c984074d52c53", "IPY_MODEL_3b7304f9f56041d986ea23a97f6a296b", "IPY_MODEL_34bb5eed32714ceca08d6f7e9f7782ca" ], "layout": "IPY_MODEL_5a339252ae104cd98bc8aeba104f617c" } }, "facf2022580948299453af6b562fe1c4": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_0211a0640ec440a6a97460916e5d4756", "placeholder": "", "style": "IPY_MODEL_440895a9c85a4c4aa9b0d00acad0601e", "value": "
Step | \n", "Training Loss | \n", "Validation Loss | \n", "Accuracy | \n", "
---|---|---|---|
100 | \n", "0.876400 | \n", "0.960147 | \n", "0.840838 | \n", "
200 | \n", "0.654800 | \n", "0.747212 | \n", "0.833508 | \n", "
300 | \n", "0.472400 | \n", "0.502757 | \n", "0.878534 | \n", "
400 | \n", "0.276400 | \n", "0.474296 | \n", "0.880628 | \n", "
500 | \n", "0.252900 | \n", "0.447288 | \n", "0.883770 | \n", "
600 | \n", "0.117900 | \n", "0.466329 | \n", "0.878534 | \n", "
700 | \n", "0.066600 | \n", "0.418198 | \n", "0.897382 | \n", "
800 | \n", "0.054800 | \n", "0.405432 | \n", "0.902618 | \n", "
900 | \n", "0.095600 | \n", "0.349726 | \n", "0.917277 | \n", "
1000 | \n", "0.017700 | \n", "0.316750 | \n", "0.912042 | \n", "
1100 | \n", "0.009400 | \n", "0.372628 | \n", "0.909948 | \n", "
1200 | \n", "0.028000 | \n", "0.331545 | \n", "0.919372 | \n", "
1300 | \n", "0.006600 | \n", "0.336132 | \n", "0.923560 | \n", "
1400 | \n", "0.006300 | \n", "0.330904 | \n", "0.923560 | \n", "
1500 | \n", "0.006200 | \n", "0.327878 | \n", "0.922513 | \n", "
"
]
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-100\n",
"Configuration saved in vit-snacks/checkpoint-100/config.json\n",
"Model weights saved in vit-snacks/checkpoint-100/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-100/preprocessor_config.json\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-200\n",
"Configuration saved in vit-snacks/checkpoint-200/config.json\n",
"Model weights saved in vit-snacks/checkpoint-200/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-200/preprocessor_config.json\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-300\n",
"Configuration saved in vit-snacks/checkpoint-300/config.json\n",
"Model weights saved in vit-snacks/checkpoint-300/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-300/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-100] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-400\n",
"Configuration saved in vit-snacks/checkpoint-400/config.json\n",
"Model weights saved in vit-snacks/checkpoint-400/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-400/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-200] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-500\n",
"Configuration saved in vit-snacks/checkpoint-500/config.json\n",
"Model weights saved in vit-snacks/checkpoint-500/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-500/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-300] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-600\n",
"Configuration saved in vit-snacks/checkpoint-600/config.json\n",
"Model weights saved in vit-snacks/checkpoint-600/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-600/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-400] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-700\n",
"Configuration saved in vit-snacks/checkpoint-700/config.json\n",
"Model weights saved in vit-snacks/checkpoint-700/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-700/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-500] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-800\n",
"Configuration saved in vit-snacks/checkpoint-800/config.json\n",
"Model weights saved in vit-snacks/checkpoint-800/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-800/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-600] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-900\n",
"Configuration saved in vit-snacks/checkpoint-900/config.json\n",
"Model weights saved in vit-snacks/checkpoint-900/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-900/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-700] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-1000\n",
"Configuration saved in vit-snacks/checkpoint-1000/config.json\n",
"Model weights saved in vit-snacks/checkpoint-1000/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-1000/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-800] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-1100\n",
"Configuration saved in vit-snacks/checkpoint-1100/config.json\n",
"Model weights saved in vit-snacks/checkpoint-1100/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-1100/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-900] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-1200\n",
"Configuration saved in vit-snacks/checkpoint-1200/config.json\n",
"Model weights saved in vit-snacks/checkpoint-1200/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-1200/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-1100] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-1300\n",
"Configuration saved in vit-snacks/checkpoint-1300/config.json\n",
"Model weights saved in vit-snacks/checkpoint-1300/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-1300/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-1200] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-1400\n",
"Configuration saved in vit-snacks/checkpoint-1400/config.json\n",
"Model weights saved in vit-snacks/checkpoint-1400/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-1400/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-1300] due to args.save_total_limit\n",
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n",
"Saving model checkpoint to vit-snacks/checkpoint-1500\n",
"Configuration saved in vit-snacks/checkpoint-1500/config.json\n",
"Model weights saved in vit-snacks/checkpoint-1500/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/checkpoint-1500/preprocessor_config.json\n",
"Deleting older checkpoint [vit-snacks/checkpoint-1400] due to args.save_total_limit\n",
"\n",
"\n",
"Training completed. Do not forget to share your model on huggingface.co/models =)\n",
"\n",
"\n",
"Loading best model from vit-snacks/checkpoint-1000 (score: 0.316749632358551).\n",
"Saving model checkpoint to vit-snacks\n",
"Configuration saved in vit-snacks/config.json\n",
"Model weights saved in vit-snacks/pytorch_model.bin\n",
"Feature extractor saved in vit-snacks/preprocessor_config.json\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"***** train metrics *****\n",
" epoch = 5.0\n",
" total_flos = 1746074896GF\n",
" train_loss = 0.2606\n",
" train_runtime = 0:19:45.83\n",
" train_samples_per_second = 20.399\n",
" train_steps_per_second = 1.278\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"metrics = trainer.evaluate(prepared_ds['validation'])\n",
"trainer.log_metrics('eval',metrics)\n",
"trainer.save_metrics('eval', metrics)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 211
},
"id": "9bFxocoW2pbf",
"outputId": "70497464-390a-4ea6-bd49-36ac22b11513"
},
"execution_count": 26,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"***** Running Evaluation *****\n",
" Num examples = 955\n",
" Batch size = 8\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"