shriarul5273 commited on
Commit
5892ebe
1 Parent(s): 6f11838

initial commit

Browse files
Files changed (8) hide show
  1. 1.jpg +0 -0
  2. 2.jpg +0 -0
  3. 3.jpg +0 -0
  4. 4.jpg +0 -0
  5. Dockerfile +12 -0
  6. app.py +57 -0
  7. model.onnx +3 -0
  8. requirements.txt +5 -0
1.jpg ADDED
2.jpg ADDED
3.jpg ADDED
4.jpg ADDED
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:20.04
2
+
3
+ RUN apt-get update && apt-get install -y \
4
+ python3 \
5
+ python3-pip && pip3 install --upgrade pip
6
+ RUN mkdir /app
7
+ COPY . /app
8
+ WORKDIR /app
9
+
10
+ RUN pip3 install -r requirements.txt
11
+
12
+ CMD ["python3", "app.py"]
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import onnxruntime
2
+ from torchvision import transforms
3
+ import torch
4
+ import torch.nn.functional as F
5
+ import gradio as gr
6
+
7
+ orst_run = onnxruntime.InferenceSession("model.onnx")
8
+
9
+ idx_to_class = {0: 'chapati',
10
+ 1: 'mukimo',
11
+ 2: 'kukuchoma',
12
+ 3: 'kachumbari',
13
+ 4: 'ugali',
14
+ 5: 'githeri',
15
+ 6: 'matoke',
16
+ 7: 'pilau',
17
+ 8: 'nyamachoma',
18
+ 9: 'sukumawiki',
19
+ 10: 'bhaji',
20
+ 11: 'mandazi',
21
+ 12: 'masalachips'}
22
+
23
+
24
+
25
+ def predict(image):
26
+ preprocess = transforms.Compose([
27
+ transforms.Resize((256,256)),
28
+ transforms.ToTensor(),
29
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
30
+ ])
31
+ input_tensor = preprocess(image)
32
+ input_batch = input_tensor.unsqueeze(0)
33
+ output = orst_run.run(None, {'input': input_batch.numpy()})
34
+ output = torch.from_numpy(output[0])
35
+
36
+ prediction=F.softmax(output,dim=1)
37
+ predProab,predIndexs = torch.topk(prediction, 3)
38
+
39
+ predProab = predProab.numpy()[0]
40
+ predIndexs = predIndexs.numpy()[0]
41
+ confidences = {idx_to_class[predIndexs[i]]: float(predProab[i]) for i in range(3)}
42
+
43
+ return confidences
44
+
45
+ def inference(img):
46
+ return predict(img)
47
+
48
+
49
+
50
+
51
+ title = 'Kenyan Food Classification'
52
+ description = "Kenyan Food Classification"
53
+
54
+ examples = ['1.jpg','2.jpg','3.jpg','4.jpg']
55
+
56
+ gr.Interface(inference, gr.Image(type="pil"), "label", server_name="0.0.0.0",title=title,
57
+ description=description, examples=examples).launch()
model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d6e03a4f838cb3dc04e1fee93ab9e2c5f51f95d244d9e6440ad1b535bc42bf97
3
+ size 27404168
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ torch==1.12.0
2
+ torchvision==0.13.0
3
+ Pillow==9.2.0
4
+ gradio==3.2.0
5
+ onnxruntime==1.12.1