piyush jain commited on
Commit
0b559b1
1 Parent(s): c641084

Initial commit with model files

Browse files
Files changed (2) hide show
  1. app.py +51 -0
  2. modelac90.weights.h5 +3 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import numpy as np
3
+ # import gradio as gr
4
+ from PIL import Image
5
+ import multiprocessing
6
+ import tensorflow as tf
7
+ # from RealESRGAN import RealESRGAN
8
+ from tensorflow.keras import layers
9
+ from tensorflow.keras.models import Model
10
+ from tensorflow.keras.optimizers import Adam
11
+ from tensorflow.keras.applications import InceptionV3
12
+
13
+
14
+ # function to return model
15
+ def create_model():
16
+ inp_shape = (200,200,3)
17
+ base_model = InceptionV3(input_shape=inp_shape, include_top=False, weights='imagenet')
18
+ x = layers.Flatten()(base_model.output)
19
+ x = layers.Dense(256, activation='relu')(x)
20
+ x = layers.Dropout(0.5)(x)
21
+
22
+ output = layers.Dense(8, activation='softmax')(x)
23
+
24
+ clf_model = Model(inputs=base_model.input, outputs=output)
25
+
26
+ clf_model.compile(optimizer=Adam(learning_rate=0.0001),
27
+ loss='categorical_crossentropy',
28
+ metrics=['accuracy'])
29
+ return clf_model
30
+
31
+ clf_model = create_model()
32
+ clf_model.load_weights('modelac90.weights.h5')
33
+
34
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
35
+
36
+ def classify_logo(inp_image):
37
+ pil_img = Image.fromarray(inp_image).resize((200,200), resample=0)
38
+ image = np.array(pil_img).astype(np.float16)/255.0
39
+ new_img = np.expand_dims(image, axis=0)
40
+ predictions = clf_model.predict(new_img)
41
+ labels = ['Adidas Fake', 'Adidas Real', 'Allen Solly Fake', 'Allen Solly Real',
42
+ 'Puma Fake', 'Puma Real', 'Us Polo Fake', 'Us Polo Real']
43
+ pred_dict = {}
44
+ for i in range(len(labels)):
45
+ pred_dict[labels[i]] = predictions[0][i]
46
+ return pred_dict
47
+
48
+ def fake_logo_detection(input_image):
49
+ print("Input image shape => ", input_image.shape)
50
+ # print("flag => ", flag)
51
+ return classify_logo(input_image)
modelac90.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad63b2d33da244b374f2e77f66450410f8eba6d689ef9b220b2994d21451b566
3
+ size 362961504