-
-
Save karthick965938/ad204df98a8da4954fde7ffd161d53a4 to your computer and use it in GitHub Desktop.
short.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "short.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyOj4fpuELdA/4bwqqcc9IzE", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/karthick965938/ad204df98a8da4954fde7ffd161d53a4/short.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "ZsRD4tlLtzaF" | |
}, | |
"source": [ | |
"Install Detecto" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "w9L_9znAUzym" | |
}, | |
"source": [ | |
"import os\n", | |
"from google.colab import drive\n", | |
"drive.mount('/content/drive')\n", | |
"os.chdir('/content/drive/My Drive/object_detection')\n", | |
"!pip install detecto" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "lTgoEj11uAc3" | |
}, | |
"source": [ | |
"Start the train your model" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "6LfC3qnltVxO" | |
}, | |
"source": [ | |
"#train your model\n", | |
"from detecto import core, utils, visualize\n", | |
"#mention you dataset path\n", | |
"dataset = core.Dataset('images/')\n", | |
"#mention you object label here\n", | |
"model = core.Model(['cat'])\n", | |
"model.fit(dataset)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "AgxMIuo4uI3a" | |
}, | |
"source": [ | |
"Test your trained model" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "1vMGKpSFtV_q" | |
}, | |
"source": [ | |
"# Specify the path to your image\n", | |
"from detecto import core, utils, visualize\n", | |
"image = utils.read_image('animals/cat48.jpg')\n", | |
"predictions = model.predict(image)\n", | |
"# predictions format: (labels, boxes, scores)\n", | |
"labels, boxes, scores = predictions\n", | |
"# ['alien', 'bat', 'bat']\n", | |
"print(labels) \n", | |
"print(boxes)\n", | |
"# tensor([0.9952, 0.9837, 0.5153])\n", | |
"print(scores)\n", | |
"visualize.show_labeled_image(image, boxes, labels)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "1A2z_X-GuXKb" | |
}, | |
"source": [ | |
"Save your trained model" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "zusZcJXussBA" | |
}, | |
"source": [ | |
"model.save('cat_model_weights.pth')\n", | |
"#use this comment to save the custom model file" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment