Skip to content

Commit ba8f7d8

Browse files
authored
colab code
1 parent 5a0836a commit ba8f7d8

File tree

1 file changed

+244
-0
lines changed

1 file changed

+244
-0
lines changed

Predict.ipynb

+244
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "Predict.ipynb",
7+
"version": "0.3.2",
8+
"provenance": [],
9+
"collapsed_sections": []
10+
},
11+
"kernelspec": {
12+
"name": "python3",
13+
"display_name": "Python 3"
14+
}
15+
},
16+
"cells": [
17+
{
18+
"metadata": {
19+
"id": "jdYV3TMGurDp",
20+
"colab_type": "code",
21+
"colab": {
22+
"base_uri": "https://localhost:8080/",
23+
"height": 649
24+
},
25+
"outputId": "d5291fe3-1b54-437a-e721-77cf837b0f2f"
26+
},
27+
"cell_type": "code",
28+
"source": [
29+
"!pip3 install --upgrade tensorflow\n",
30+
"!pip3 install h5py\n",
31+
"!pip3 install keras\n",
32+
"!pip3 install https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.2/imageai-2.0.2-py3-none-any.whl\n"
33+
],
34+
"execution_count": 1,
35+
"outputs": [
36+
{
37+
"output_type": "stream",
38+
"text": [
39+
"Requirement already up-to-date: tensorflow in /usr/local/lib/python3.6/dist-packages (1.13.1)\n",
40+
"Requirement already satisfied, skipping upgrade: termcolor>=1.1.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (1.1.0)\n",
41+
"Requirement already satisfied, skipping upgrade: absl-py>=0.1.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (0.7.1)\n",
42+
"Requirement already satisfied, skipping upgrade: grpcio>=1.8.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (1.15.0)\n",
43+
"Requirement already satisfied, skipping upgrade: wheel>=0.26 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (0.33.1)\n",
44+
"Requirement already satisfied, skipping upgrade: tensorflow-estimator<1.14.0rc0,>=1.13.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (1.13.0)\n",
45+
"Requirement already satisfied, skipping upgrade: tensorboard<1.14.0,>=1.13.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (1.13.1)\n",
46+
"Requirement already satisfied, skipping upgrade: keras-applications>=1.0.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (1.0.7)\n",
47+
"Requirement already satisfied, skipping upgrade: gast>=0.2.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (0.2.2)\n",
48+
"Requirement already satisfied, skipping upgrade: astor>=0.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (0.7.1)\n",
49+
"Requirement already satisfied, skipping upgrade: numpy>=1.13.3 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (1.16.3)\n",
50+
"Requirement already satisfied, skipping upgrade: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (1.12.0)\n",
51+
"Requirement already satisfied, skipping upgrade: protobuf>=3.6.1 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (3.7.1)\n",
52+
"Requirement already satisfied, skipping upgrade: keras-preprocessing>=1.0.5 in /usr/local/lib/python3.6/dist-packages (from tensorflow) (1.0.9)\n",
53+
"Requirement already satisfied, skipping upgrade: mock>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow-estimator<1.14.0rc0,>=1.13.0->tensorflow) (2.0.0)\n",
54+
"Requirement already satisfied, skipping upgrade: markdown>=2.6.8 in /usr/local/lib/python3.6/dist-packages (from tensorboard<1.14.0,>=1.13.0->tensorflow) (3.1)\n",
55+
"Requirement already satisfied, skipping upgrade: werkzeug>=0.11.15 in /usr/local/lib/python3.6/dist-packages (from tensorboard<1.14.0,>=1.13.0->tensorflow) (0.15.2)\n",
56+
"Requirement already satisfied, skipping upgrade: h5py in /usr/local/lib/python3.6/dist-packages (from keras-applications>=1.0.6->tensorflow) (2.8.0)\n",
57+
"Requirement already satisfied, skipping upgrade: setuptools in /usr/local/lib/python3.6/dist-packages (from protobuf>=3.6.1->tensorflow) (40.9.0)\n",
58+
"Requirement already satisfied, skipping upgrade: pbr>=0.11 in /usr/local/lib/python3.6/dist-packages (from mock>=2.0.0->tensorflow-estimator<1.14.0rc0,>=1.13.0->tensorflow) (5.1.3)\n",
59+
"Requirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages (2.8.0)\n",
60+
"Requirement already satisfied: numpy>=1.7 in /usr/local/lib/python3.6/dist-packages (from h5py) (1.16.3)\n",
61+
"Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from h5py) (1.12.0)\n",
62+
"Requirement already satisfied: keras in /usr/local/lib/python3.6/dist-packages (2.2.4)\n",
63+
"Requirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages (from keras) (2.8.0)\n",
64+
"Requirement already satisfied: scipy>=0.14 in /usr/local/lib/python3.6/dist-packages (from keras) (1.2.1)\n",
65+
"Requirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python3.6/dist-packages (from keras) (1.16.3)\n",
66+
"Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from keras) (3.13)\n",
67+
"Requirement already satisfied: keras-preprocessing>=1.0.5 in /usr/local/lib/python3.6/dist-packages (from keras) (1.0.9)\n",
68+
"Requirement already satisfied: keras-applications>=1.0.6 in /usr/local/lib/python3.6/dist-packages (from keras) (1.0.7)\n",
69+
"Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.6/dist-packages (from keras) (1.12.0)\n",
70+
"Collecting imageai==2.0.2 from https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.2/imageai-2.0.2-py3-none-any.whl\n",
71+
"\u001b[?25l Downloading https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.2/imageai-2.0.2-py3-none-any.whl (151kB)\n",
72+
"\u001b[K 100% |████████████████████████████████| 153kB 2.4MB/s \n",
73+
"\u001b[?25hInstalling collected packages: imageai\n",
74+
"Successfully installed imageai-2.0.2\n"
75+
],
76+
"name": "stdout"
77+
}
78+
]
79+
},
80+
{
81+
"metadata": {
82+
"id": "EDzPSJ6Vv1VC",
83+
"colab_type": "code",
84+
"colab": {
85+
"base_uri": "https://localhost:8080/",
86+
"height": 309
87+
},
88+
"outputId": "1e4ff874-42a1-4903-88b2-99c53c758704"
89+
},
90+
"cell_type": "code",
91+
"source": [
92+
"!wget https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo.h5"
93+
],
94+
"execution_count": 3,
95+
"outputs": [
96+
{
97+
"output_type": "stream",
98+
"text": [
99+
"--2019-04-28 21:01:51-- https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo.h5\n",
100+
"Resolving github.com (github.com)... 192.30.253.113, 192.30.253.112\n",
101+
"Connecting to github.com (github.com)|192.30.253.113|:443... connected.\n",
102+
"HTTP request sent, awaiting response... 302 Found\n",
103+
"Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/125932201/1b8496e8-86fc-11e8-895f-fefe61ebb499?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190428%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190428T210152Z&X-Amz-Expires=300&X-Amz-Signature=9f5c6d37a6e197cc773a009ff55cc97bbe1200352b4f6a97525169303c082669&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dyolo.h5&response-content-type=application%2Foctet-stream [following]\n",
104+
"--2019-04-28 21:01:52-- https://github-production-release-asset-2e65be.s3.amazonaws.com/125932201/1b8496e8-86fc-11e8-895f-fefe61ebb499?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190428%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190428T210152Z&X-Amz-Expires=300&X-Amz-Signature=9f5c6d37a6e197cc773a009ff55cc97bbe1200352b4f6a97525169303c082669&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dyolo.h5&response-content-type=application%2Foctet-stream\n",
105+
"Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.216.10.171\n",
106+
"Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.10.171|:443... connected.\n",
107+
"HTTP request sent, awaiting response... 200 OK\n",
108+
"Length: 248686624 (237M) [application/octet-stream]\n",
109+
"Saving to: ‘yolo.h5.1’\n",
110+
"\n",
111+
"yolo.h5.1 100%[===================>] 237.17M 98.4MB/s in 2.4s \n",
112+
"\n",
113+
"2019-04-28 21:01:54 (98.4 MB/s) - ‘yolo.h5.1’ saved [248686624/248686624]\n",
114+
"\n"
115+
],
116+
"name": "stdout"
117+
}
118+
]
119+
},
120+
{
121+
"metadata": {
122+
"id": "L0qVrLI1wZcT",
123+
"colab_type": "code",
124+
"colab": {
125+
"base_uri": "https://localhost:8080/",
126+
"height": 105
127+
},
128+
"outputId": "a8108042-e573-4e3b-de77-6d3f867b3380"
129+
},
130+
"cell_type": "code",
131+
"source": [
132+
"from imageai.Detection import ObjectDetection\n",
133+
"import os\n",
134+
"\n",
135+
"execution_path = os.getcwd()\n",
136+
"\n",
137+
"\n",
138+
"detector = ObjectDetection()\n",
139+
"detector.setModelTypeAsYOLOv3()\n",
140+
"detector.setModelPath( os.path.join(execution_path , \"yolo.h5\"))\n",
141+
"detector.loadModel()\n"
142+
],
143+
"execution_count": 4,
144+
"outputs": [
145+
{
146+
"output_type": "stream",
147+
"text": [
148+
"Using TensorFlow backend.\n"
149+
],
150+
"name": "stderr"
151+
},
152+
{
153+
"output_type": "stream",
154+
"text": [
155+
"WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
156+
"Instructions for updating:\n",
157+
"Colocations handled automatically by placer.\n"
158+
],
159+
"name": "stdout"
160+
}
161+
]
162+
},
163+
{
164+
"metadata": {
165+
"id": "JEw16R2a1rRF",
166+
"colab_type": "code",
167+
"colab": {
168+
"base_uri": "https://localhost:8080/",
169+
"height": 122
170+
},
171+
"outputId": "954645e9-1d0b-493e-bd8b-586f5bdfa4ba"
172+
},
173+
"cell_type": "code",
174+
"source": [
175+
"from google.colab import drive\n",
176+
"drive.mount('/content/gdrive')"
177+
],
178+
"execution_count": 7,
179+
"outputs": [
180+
{
181+
"output_type": "stream",
182+
"text": [
183+
"Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdocs.test%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fpeopleapi.readonly&response_type=code\n",
184+
"\n",
185+
"Enter your authorization code:\n",
186+
"··········\n",
187+
"Mounted at /content/gdrive\n"
188+
],
189+
"name": "stdout"
190+
}
191+
]
192+
},
193+
{
194+
"metadata": {
195+
"id": "QRwlM_n71raD",
196+
"colab_type": "code",
197+
"colab": {
198+
"base_uri": "https://localhost:8080/",
199+
"height": 153
200+
},
201+
"outputId": "9fdb60f1-aedf-4b70-ee0f-c58e849f6e0d"
202+
},
203+
"cell_type": "code",
204+
"source": [
205+
"detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , \"/content/gdrive/My Drive/objects.jpg\"), output_image_path=os.path.join(execution_path , \"/content/gdrive/My Drive/output.jpg\"), minimum_percentage_probability=30)\n",
206+
"\n",
207+
"\n",
208+
"for eachObject in detections:\n",
209+
" print(eachObject[\"name\"] , \" : \", eachObject[\"percentage_probability\"], \" : \", eachObject[\"box_points\"] )\n",
210+
"print(\"--------------------------------\")\n"
211+
],
212+
"execution_count": 11,
213+
"outputs": [
214+
{
215+
"output_type": "stream",
216+
"text": [
217+
"handbag : 54.47157621383667 : (1061, 687, 1240, 1062)\n",
218+
"car : 51.82286500930786 : (1407, 117, 1670, 233)\n",
219+
"car : 83.58903527259827 : (7, 304, 267, 1104)\n",
220+
"bicycle : 97.85240888595581 : (318, 433, 666, 772)\n",
221+
"person : 99.87272620201111 : (2050, 61, 2250, 1203)\n",
222+
"person : 99.88183975219727 : (1502, 142, 1728, 751)\n",
223+
"person : 99.913889169693 : (1138, 125, 1669, 1421)\n",
224+
"--------------------------------\n"
225+
],
226+
"name": "stdout"
227+
}
228+
]
229+
},
230+
{
231+
"metadata": {
232+
"id": "Tz6PpbVu1rb0",
233+
"colab_type": "code",
234+
"colab": {}
235+
},
236+
"cell_type": "code",
237+
"source": [
238+
""
239+
],
240+
"execution_count": 0,
241+
"outputs": []
242+
}
243+
]
244+
}

0 commit comments

Comments
 (0)