Spaces:
Running
Running
path errors
Browse files- app.py +3 -3
- classifier.ipynb +48 -3
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
-
|
4 |
# Load a pre-trained image classification model
|
5 |
-
learn = load_learner('models/model.pth')
|
6 |
|
7 |
# Function to make predictions from an image
|
8 |
def classify_image(image):
|
@@ -12,7 +12,7 @@ def classify_image(image):
|
|
12 |
return name[0]
|
13 |
|
14 |
# Sample images for user to choose from
|
15 |
-
sample_images = ["AcuraTLType-S2008.jpg", "AudiR8Coupe2012.jpg", "DodgeMagnumWagon2008.jpg"]
|
16 |
|
17 |
iface = gr.Interface(
|
18 |
fn=classify_image,
|
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
+
import os
|
4 |
# Load a pre-trained image classification model
|
5 |
+
learn = load_learner('./models/model.pth')
|
6 |
|
7 |
# Function to make predictions from an image
|
8 |
def classify_image(image):
|
|
|
12 |
return name[0]
|
13 |
|
14 |
# Sample images for user to choose from
|
15 |
+
sample_images = ["./sample_images/AcuraTLType-S2008.jpg", "./sample_images/AudiR8Coupe2012.jpg", "./sample_images/DodgeMagnumWagon2008.jpg"]
|
16 |
|
17 |
iface = gr.Interface(
|
18 |
fn=classify_image,
|
classifier.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"id": "6afcec5d",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
@@ -471,7 +471,9 @@
|
|
471 |
"cell_type": "code",
|
472 |
"execution_count": 43,
|
473 |
"id": "e1a3390f-e4f6-480e-b6de-377bfa7cd1a1",
|
474 |
-
"metadata": {
|
|
|
|
|
475 |
"outputs": [
|
476 |
{
|
477 |
"data": {
|
@@ -830,9 +832,52 @@
|
|
830 |
},
|
831 |
{
|
832 |
"cell_type": "code",
|
833 |
-
"execution_count":
|
834 |
"id": "b998feae-2c0e-4cee-ab26-73d87b52c7f6",
|
835 |
"metadata": {},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
836 |
"outputs": [],
|
837 |
"source": []
|
838 |
}
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 60,
|
6 |
"id": "6afcec5d",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
|
|
471 |
"cell_type": "code",
|
472 |
"execution_count": 43,
|
473 |
"id": "e1a3390f-e4f6-480e-b6de-377bfa7cd1a1",
|
474 |
+
"metadata": {
|
475 |
+
"scrolled": true
|
476 |
+
},
|
477 |
"outputs": [
|
478 |
{
|
479 |
"data": {
|
|
|
832 |
},
|
833 |
{
|
834 |
"cell_type": "code",
|
835 |
+
"execution_count": 58,
|
836 |
"id": "b998feae-2c0e-4cee-ab26-73d87b52c7f6",
|
837 |
"metadata": {},
|
838 |
+
"outputs": [
|
839 |
+
{
|
840 |
+
"ename": "NameError",
|
841 |
+
"evalue": "name 'gr' is not defined",
|
842 |
+
"output_type": "error",
|
843 |
+
"traceback": [
|
844 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
845 |
+
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
846 |
+
"Cell \u001b[1;32mIn[58], line 10\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;66;03m# Sample images for user to choose from\u001b[39;00m\n\u001b[0;32m 8\u001b[0m sample_images \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAcuraTLType-S2008.jpg\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAudiR8Coupe2012.jpg\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDodgeMagnumWagon2008.jpg\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m---> 10\u001b[0m iface \u001b[38;5;241m=\u001b[39m \u001b[43mgr\u001b[49m\u001b[38;5;241m.\u001b[39mInterface(\n\u001b[0;32m 11\u001b[0m fn\u001b[38;5;241m=\u001b[39mclassify_image,\n\u001b[0;32m 12\u001b[0m inputs\u001b[38;5;241m=\u001b[39mgr\u001b[38;5;241m.\u001b[39mImage(label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSelect an image\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28mtype\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfilepath\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m 13\u001b[0m outputs\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtext\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 14\u001b[0m live\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m 15\u001b[0m title\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCar image classifier\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 16\u001b[0m description\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUpload a car image or select one of the examples below\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 17\u001b[0m examples\u001b[38;5;241m=\u001b[39msample_images\n\u001b[0;32m 18\u001b[0m )\n\u001b[0;32m 21\u001b[0m iface\u001b[38;5;241m.\u001b[39mlaunch()\n",
|
847 |
+
"\u001b[1;31mNameError\u001b[0m: name 'gr' is not defined"
|
848 |
+
]
|
849 |
+
}
|
850 |
+
],
|
851 |
+
"source": []
|
852 |
+
},
|
853 |
+
{
|
854 |
+
"cell_type": "code",
|
855 |
+
"execution_count": 63,
|
856 |
+
"id": "4b498d88-8f82-4f30-b43d-d0d1d87e0fa8",
|
857 |
+
"metadata": {},
|
858 |
+
"outputs": [
|
859 |
+
{
|
860 |
+
"ename": "AttributeError",
|
861 |
+
"evalue": "'collections.OrderedDict' object has no attribute 'dls'",
|
862 |
+
"output_type": "error",
|
863 |
+
"traceback": [
|
864 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
865 |
+
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
866 |
+
"Cell \u001b[1;32mIn[63], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mload_learner\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mmodels/model.pth\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
|
867 |
+
"File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\fastai\\learner.py:451\u001b[0m, in \u001b[0;36mload_learner\u001b[1;34m(fname, cpu, pickle_module)\u001b[0m\n\u001b[0;32m 449\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m\n\u001b[0;32m 450\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cpu: \n\u001b[1;32m--> 451\u001b[0m \u001b[43mres\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdls\u001b[49m\u001b[38;5;241m.\u001b[39mcpu()\n\u001b[0;32m 452\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(res, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mchannels_last\u001b[39m\u001b[38;5;124m'\u001b[39m): res \u001b[38;5;241m=\u001b[39m res\u001b[38;5;241m.\u001b[39mto_contiguous(to_fp32\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m 453\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(res, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmixed_precision\u001b[39m\u001b[38;5;124m'\u001b[39m): res \u001b[38;5;241m=\u001b[39m res\u001b[38;5;241m.\u001b[39mto_fp32()\n",
|
868 |
+
"\u001b[1;31mAttributeError\u001b[0m: 'collections.OrderedDict' object has no attribute 'dls'"
|
869 |
+
]
|
870 |
+
}
|
871 |
+
],
|
872 |
+
"source": [
|
873 |
+
"load_learner('models/model.pth')"
|
874 |
+
]
|
875 |
+
},
|
876 |
+
{
|
877 |
+
"cell_type": "code",
|
878 |
+
"execution_count": null,
|
879 |
+
"id": "4cab2e5a-9cd3-42c1-8241-5a55475fd886",
|
880 |
+
"metadata": {},
|
881 |
"outputs": [],
|
882 |
"source": []
|
883 |
}
|