Spaces:
Sleeping
Sleeping
Nullzero
commited on
Commit
·
ed62081
1
Parent(s):
277915b
final commit
Browse files- app.py +40 -0
- export.pkl +3 -0
- requirements.txt +82 -0
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''PyTorch Food Classifier - FastAI 2022- Mostly Good For Pastries
|
| 2 |
+
and trained on ResNet 34'''
|
| 3 |
+
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import time
|
| 8 |
+
from fastai.vision.all import *
|
| 9 |
+
from fastai.learner import load_learner
|
| 10 |
+
|
| 11 |
+
def GetLabel(img):
|
| 12 |
+
return img.split('-')[0]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
#Load the Learner (Exported from ipnyb file with learn.export() )
|
| 16 |
+
learn = load_learner('export.pkl')
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
#Classify image
|
| 20 |
+
def classify_image(cl_img):
|
| 21 |
+
img = Image.open(cl_img)
|
| 22 |
+
st.image(img)
|
| 23 |
+
pred, _ , _ = learn.predict(img)
|
| 24 |
+
return pred
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
st.set_page_config(page_title="PyTorch Food Classifier - FastAI 2022", page_icon=":robot:")
|
| 30 |
+
st.header("PyTorch Food Classifier")
|
| 31 |
+
|
| 32 |
+
file_up = st.file_uploader("Upload Your Food Image Below", type=["jpg","png"])
|
| 33 |
+
|
| 34 |
+
if st.button('Run Model'):
|
| 35 |
+
st.write("Button Pressed")
|
| 36 |
+
cl_done = classify_image(file_up)
|
| 37 |
+
|
| 38 |
+
st.write(f"Your food is: {cl_done}")
|
| 39 |
+
|
| 40 |
+
st.write('This classifier is trained on Resnet-34 and works primarily for three classes. Donuts, CheeseCake and Panna Cotta (HOTDOGNOTHOTDOG).\n\n Thankyou to FastAI for the exercise.')
|
export.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:696cf7b0a2c49e3795efc915c0744058120083e58eba2dba0cb57a2ddc6d87eb
|
| 3 |
+
size 87520254
|
requirements.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
altair==4.2.2
|
| 2 |
+
attrs==22.2.0
|
| 3 |
+
blinker==1.5
|
| 4 |
+
blis==0.7.9
|
| 5 |
+
cachetools==5.3.0
|
| 6 |
+
catalogue==2.0.8
|
| 7 |
+
certifi==2022.12.7
|
| 8 |
+
charset-normalizer==3.1.0
|
| 9 |
+
click==8.1.3
|
| 10 |
+
confection==0.0.4
|
| 11 |
+
contourpy==1.0.7
|
| 12 |
+
cycler==0.11.0
|
| 13 |
+
cymem==2.0.7
|
| 14 |
+
decorator==5.1.1
|
| 15 |
+
entrypoints==0.4
|
| 16 |
+
fastai==2.7.11
|
| 17 |
+
fastcore==1.5.28
|
| 18 |
+
fastdownload==0.0.7
|
| 19 |
+
fastprogress==1.0.3
|
| 20 |
+
fonttools==4.39.2
|
| 21 |
+
gitdb==4.0.10
|
| 22 |
+
GitPython==3.1.31
|
| 23 |
+
idna==3.4
|
| 24 |
+
importlib-metadata==6.1.0
|
| 25 |
+
Jinja2==3.1.2
|
| 26 |
+
joblib==1.2.0
|
| 27 |
+
jsonschema==4.17.3
|
| 28 |
+
kiwisolver==1.4.4
|
| 29 |
+
langcodes==3.3.0
|
| 30 |
+
markdown-it-py==2.2.0
|
| 31 |
+
MarkupSafe==2.1.2
|
| 32 |
+
matplotlib==3.7.1
|
| 33 |
+
mdurl==0.1.2
|
| 34 |
+
murmurhash==1.0.9
|
| 35 |
+
numpy==1.24.2
|
| 36 |
+
olefile==0.46
|
| 37 |
+
packaging==23.0
|
| 38 |
+
pandas==1.5.3
|
| 39 |
+
pathy==0.10.1
|
| 40 |
+
Pillow==9.4.0
|
| 41 |
+
preshed==3.0.8
|
| 42 |
+
protobuf==3.20.3
|
| 43 |
+
pyarrow==11.0.0
|
| 44 |
+
pydantic==1.10.7
|
| 45 |
+
pydeck==0.8.0
|
| 46 |
+
Pygments==2.14.0
|
| 47 |
+
Pympler==1.0.1
|
| 48 |
+
pyparsing==3.0.9
|
| 49 |
+
pyrsistent==0.19.3
|
| 50 |
+
python-dateutil==2.8.2
|
| 51 |
+
pytz==2022.7.1
|
| 52 |
+
pytz-deprecation-shim==0.1.0.post0
|
| 53 |
+
PyYAML==6.0
|
| 54 |
+
requests==2.28.2
|
| 55 |
+
rich==13.3.2
|
| 56 |
+
scikit-learn==1.2.2
|
| 57 |
+
scipy==1.10.1
|
| 58 |
+
semver==2.13.0
|
| 59 |
+
six==1.16.0
|
| 60 |
+
smart-open==6.3.0
|
| 61 |
+
smmap==5.0.0
|
| 62 |
+
spacy==3.5.1
|
| 63 |
+
spacy-legacy==3.0.12
|
| 64 |
+
spacy-loggers==1.0.4
|
| 65 |
+
srsly==2.4.6
|
| 66 |
+
streamlit==1.20.0
|
| 67 |
+
thinc==8.1.9
|
| 68 |
+
threadpoolctl==3.1.0
|
| 69 |
+
toml==0.10.2
|
| 70 |
+
toolz==0.12.0
|
| 71 |
+
torch==1.13.1
|
| 72 |
+
torchvision==0.14.1
|
| 73 |
+
tornado==6.2
|
| 74 |
+
tqdm==4.65.0
|
| 75 |
+
typer==0.7.0
|
| 76 |
+
typing_extensions==4.5.0
|
| 77 |
+
tzdata==2022.7
|
| 78 |
+
tzlocal==4.3
|
| 79 |
+
urllib3==1.26.15
|
| 80 |
+
validators==0.20.0
|
| 81 |
+
wasabi==1.1.1
|
| 82 |
+
zipp==3.15.0
|