Spaces:
Running
Running
example pushed
Browse files- .ipynb_checkpoints/classifier-checkpoint.ipynb +113 -2
- app.py +5 -3
- classifier.ipynb +0 -0
.ipynb_checkpoints/classifier-checkpoint.ipynb
CHANGED
@@ -1,6 +1,117 @@
|
|
1 |
{
|
2 |
-
"cells": [
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
"nbformat": 4,
|
5 |
"nbformat_minor": 5
|
6 |
}
|
|
|
1 |
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "6afcec5d",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import fastbook\n",
|
11 |
+
"fastbook.setup_book()"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": 2,
|
17 |
+
"id": "4e4f004b",
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [],
|
20 |
+
"source": [
|
21 |
+
"from fastai.vision.all import *"
|
22 |
+
]
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"cell_type": "code",
|
26 |
+
"execution_count": 14,
|
27 |
+
"id": "c27d35cd",
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": [
|
31 |
+
"import scipy.io\n",
|
32 |
+
"import os\n",
|
33 |
+
"import numpy as np"
|
34 |
+
]
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"cell_type": "code",
|
38 |
+
"execution_count": 18,
|
39 |
+
"id": "1698b023",
|
40 |
+
"metadata": {
|
41 |
+
"scrolled": true
|
42 |
+
},
|
43 |
+
"outputs": [],
|
44 |
+
"source": [
|
45 |
+
"# Load a MAT file\n",
|
46 |
+
"mat_p = os.path.join(os.getcwd(),'data','cars_annos.mat')\n",
|
47 |
+
"mat = scipy.io.loadmat(mat_p)\n",
|
48 |
+
"annotations = mat['annotations']\n",
|
49 |
+
"class_names = mat['class_names']"
|
50 |
+
]
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"cell_type": "code",
|
54 |
+
"execution_count": 19,
|
55 |
+
"id": "b4402e00",
|
56 |
+
"metadata": {},
|
57 |
+
"outputs": [],
|
58 |
+
"source": [
|
59 |
+
"annotations = np.array(annotations[0])"
|
60 |
+
]
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"cell_type": "code",
|
64 |
+
"execution_count": 31,
|
65 |
+
"id": "ef6b02ad",
|
66 |
+
"metadata": {},
|
67 |
+
"outputs": [
|
68 |
+
{
|
69 |
+
"ename": "ValueError",
|
70 |
+
"evalue": "setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (7, 1) + inhomogeneous part.",
|
71 |
+
"output_type": "error",
|
72 |
+
"traceback": [
|
73 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
74 |
+
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
|
75 |
+
"Cell \u001b[1;32mIn[31], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m annotations \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mvectorize(np\u001b[38;5;241m.\u001b[39marray)(annotations)\n",
|
76 |
+
"File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\numpy\\lib\\function_base.py:2372\u001b[0m, in \u001b[0;36mvectorize.__call__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 2369\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_init_stage_2(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 2370\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\n\u001b[1;32m-> 2372\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call_as_normal(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
|
77 |
+
"File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\numpy\\lib\\function_base.py:2365\u001b[0m, in \u001b[0;36mvectorize._call_as_normal\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 2362\u001b[0m vargs \u001b[38;5;241m=\u001b[39m [args[_i] \u001b[38;5;28;01mfor\u001b[39;00m _i \u001b[38;5;129;01min\u001b[39;00m inds]\n\u001b[0;32m 2363\u001b[0m vargs\u001b[38;5;241m.\u001b[39mextend([kwargs[_n] \u001b[38;5;28;01mfor\u001b[39;00m _n \u001b[38;5;129;01min\u001b[39;00m names])\n\u001b[1;32m-> 2365\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_vectorize_call(func\u001b[38;5;241m=\u001b[39mfunc, args\u001b[38;5;241m=\u001b[39mvargs)\n",
|
78 |
+
"File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\numpy\\lib\\function_base.py:2455\u001b[0m, in \u001b[0;36mvectorize._vectorize_call\u001b[1;34m(self, func, args)\u001b[0m\n\u001b[0;32m 2452\u001b[0m \u001b[38;5;66;03m# Convert args to object arrays first\u001b[39;00m\n\u001b[0;32m 2453\u001b[0m inputs \u001b[38;5;241m=\u001b[39m [asanyarray(a, dtype\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mobject\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m a \u001b[38;5;129;01min\u001b[39;00m args]\n\u001b[1;32m-> 2455\u001b[0m outputs \u001b[38;5;241m=\u001b[39m ufunc(\u001b[38;5;241m*\u001b[39minputs)\n\u001b[0;32m 2457\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ufunc\u001b[38;5;241m.\u001b[39mnout \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m 2458\u001b[0m res \u001b[38;5;241m=\u001b[39m asanyarray(outputs, dtype\u001b[38;5;241m=\u001b[39motypes[\u001b[38;5;241m0\u001b[39m])\n",
|
79 |
+
"\u001b[1;31mValueError\u001b[0m: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (7, 1) + inhomogeneous part."
|
80 |
+
]
|
81 |
+
}
|
82 |
+
],
|
83 |
+
"source": [
|
84 |
+
"annotations = np.where(annotations, np.arary(annotations), np.arary(annotations))"
|
85 |
+
]
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"cell_type": "code",
|
89 |
+
"execution_count": null,
|
90 |
+
"id": "73630f27",
|
91 |
+
"metadata": {},
|
92 |
+
"outputs": [],
|
93 |
+
"source": []
|
94 |
+
}
|
95 |
+
],
|
96 |
+
"metadata": {
|
97 |
+
"kernelspec": {
|
98 |
+
"display_name": "Python [conda env:hf]",
|
99 |
+
"language": "python",
|
100 |
+
"name": "conda-env-hf-py"
|
101 |
+
},
|
102 |
+
"language_info": {
|
103 |
+
"codemirror_mode": {
|
104 |
+
"name": "ipython",
|
105 |
+
"version": 3
|
106 |
+
},
|
107 |
+
"file_extension": ".py",
|
108 |
+
"mimetype": "text/x-python",
|
109 |
+
"name": "python",
|
110 |
+
"nbconvert_exporter": "python",
|
111 |
+
"pygments_lexer": "ipython3",
|
112 |
+
"version": "3.11.6"
|
113 |
+
}
|
114 |
+
},
|
115 |
"nbformat": 4,
|
116 |
"nbformat_minor": 5
|
117 |
}
|
app.py
CHANGED
@@ -14,18 +14,20 @@ def classify_image(image):
|
|
14 |
|
15 |
# Decode the prediction and get the class name
|
16 |
class_name = np.random.randint(0,3)
|
17 |
-
classes = ["
|
18 |
return classes[class_name]
|
19 |
|
20 |
# Sample images for user to choose from
|
21 |
-
sample_images = ["
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
fn=classify_image,
|
25 |
-
inputs=gr.
|
26 |
outputs="text",
|
27 |
live=True,
|
|
|
28 |
examples=sample_images
|
29 |
)
|
30 |
|
|
|
31 |
iface.launch()
|
|
|
14 |
|
15 |
# Decode the prediction and get the class name
|
16 |
class_name = np.random.randint(0,3)
|
17 |
+
classes = ["Acura", "Audi", "Dodge"]
|
18 |
return classes[class_name]
|
19 |
|
20 |
# Sample images for user to choose from
|
21 |
+
sample_images = ["AcuraTLType-S2008.jpg", "AudiR8Coupe2012.jpg", "DodgeMagnumWagon2008.jpg"]
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
fn=classify_image,
|
25 |
+
inputs=gr.Image(label="Select an image", type="file",shape=(200, 200)),
|
26 |
outputs="text",
|
27 |
live=True,
|
28 |
+
title="Identify the car"
|
29 |
examples=sample_images
|
30 |
)
|
31 |
|
32 |
+
|
33 |
iface.launch()
|
classifier.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|