File size: 3,357 Bytes
5388fd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# # -*- coding: utf-8 -*-
# """app creation.ipynb

# Automatically generated by Colaboratory.

# Original file is located at
#     https://colab.research.google.com/drive/1c8HIdMTAJxhNiPY7_kmzP78yFiwdhh8Q
# """

# import gradio as gr
# from fastai import *
# from fastai.vision.all import *

# # import pathlib
# # temp = pathlib.PosixPath
# # pathlib.PosixPath = pathlib.WindowsPath

# model = load_learner("models/recgonizer_model.pkl")

# labels = ['Ayre', 'Catla', 'Chital', 'Ilish', 'Kachki', 'Kajoli', 'Koi', 'Magur', 'Mola Dhela', 'Mrigal', 'Pabda', 'Pangash', 'Poa', 'Puti', 'Rui', 'Shing', 'Silver Carp', 'Taki', 'Telapia', 'Tengra']

# def recognize_image(image_path):
#   label, _, probs = model.predict(image_path)
#   return dict(zip(labels, map(float, probs)))

# inputs = gr.inputs.Image(shape=(224,224))
# outputs = gr.outputs.Label()

# examples = [
#     'test images/unknown_01.jpg',
#     'test images/unknown_02.png',
#     'test images/unknown_03.jpg',
#     'test images/unknown_04.jpg',
#     'test images/unknown_05.jpg',
#     'test images/unknown_06.jpg',
#     'test images/unknown_07.jpg',
#     'test images/unknown_08.jpg',
#     'test images/unknown_09.jpg',
#     'test images/unknown_10.jpg',
#     'test images/unknown_11.jpg',
#     'test images/unknown_12.png',
#     'test images/unknown_13.jpg',
#     'test images/unknown_14.png',
#     'test images/unknown_15.png',
#     'test images/unknown_16.png',
#     'test images/unknown_17.jpg'
# ]

# interface = gr.Interface(fn=recognize_image, inputs = inputs, outputs=outputs, examples = examples)

# interface.launch()




# -*- coding: utf-8 -*-
"""app creation.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1c8HIdMTAJxhNiPY7_kmzP78yFiwdhh8Q
"""

import numpy as np
import gradio as gr
from fastai import *
from fastai.vision.all import *

import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath

model = load_learner("models/recgonizer_model.pkl")

labels = ['Ayre', 'Catla', 'Chital', 'Ilish', 'Kachki', 'Kajoli', 'Koi', 'Magur', 'Mola Dhela', 'Mrigal', 'Pabda', 'Pangash', 'Poa', 'Puti', 'Rui', 'Shing', 'Silver Carp', 'Taki', 'Telapia', 'Tengra']

def recognize_image(image_path):
  label, _, probs = model.predict(image_path)
  # return dict(zip(labels, map(float, probs)))
  print(f"Category with most probability: {np.argmax(probs)}")
  return image_path, dict(zip(labels, map(float, probs)))

# inputs = gr.inputs.Image(shape=(224,224))
# outputs = gr.outputs.Label()

examples = [
    'test images/unknown_01.jpg',
    'test images/unknown_02.png',
    'test images/unknown_03.jpg',
    'test images/unknown_04.jpg',
    'test images/unknown_05.jpg',
    'test images/unknown_06.jpg',
    'test images/unknown_07.jpg',
    'test images/unknown_08.jpg',
    'test images/unknown_09.jpg',
    'test images/unknown_10.jpg',
    'test images/unknown_11.jpg',
    'test images/unknown_12.png',
    'test images/unknown_13.jpg',
    'test images/unknown_14.png',
    'test images/unknown_15.png',
    'test images/unknown_16.png',
    'test images/unknown_17.jpg'
]

interface = gr.Interface(fn=recognize_image, inputs = gr.Image(), outputs = [gr.Image(height=224, width=224), gr.Label(num_top_classes=5)] , examples = examples)

interface.launch()