vahidrezanezhad commited on
Commit
53d0fd5
1 Parent(s): af99749

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -26
app.py CHANGED
@@ -74,7 +74,88 @@ def return_num_columns(img):
74
  label_p_pred = model_classifier.predict(img_in, verbose=0)
75
  num_col = np.argmax(label_p_pred[0]) + 1
76
  return num_col
77
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  def do_prediction(model_name, img):
79
  img_org = np.copy(img)
80
  model = from_pretrained_keras(model_name)
@@ -110,33 +191,11 @@ def do_prediction(model_name, img):
110
  img_width_h = img_org.shape[1]
111
 
112
  num_col_classifier = return_num_columns(img)
 
113
 
114
 
115
-
116
- if num_col_classifier == 1:
117
- img_w_new = 1000
118
- img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
119
-
120
- elif num_col_classifier == 2:
121
- img_w_new = 1500
122
- img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
123
-
124
- elif num_col_classifier == 3:
125
- img_w_new = 2000
126
- img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
127
-
128
- elif num_col_classifier == 4:
129
- img_w_new = 2500
130
- img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
131
- elif num_col_classifier == 5:
132
- img_w_new = 3000
133
- img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
134
- else:
135
- img_w_new = 4000
136
- img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
137
- img_resized = resize_image(img,img_h_new, img_w_new )
138
-
139
- img = otsu_copy_binary(img_resized)
140
 
141
 
142
 
 
74
  label_p_pred = model_classifier.predict(img_in, verbose=0)
75
  num_col = np.argmax(label_p_pred[0]) + 1
76
  return num_col
77
+
78
+ def return_scaled_image(img, num_col, width_early, model_name):
79
+ if model_name== ("SBB/eynollah-main-regions-aug-rotation" | "SBB/eynollah-main-regions-aug-scaling" | "SBB/eynollah-main-regions-ensembled"):
80
+ if num_col == 1 and width_early < 1100:
81
+ img_w_new = 2000
82
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 2000)
83
+ elif num_col == 1 and width_early >= 2500:
84
+ img_w_new = 2000
85
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 2000)
86
+ elif num_col == 1 and width_early >= 1100 and width_early < 2500:
87
+ img_w_new = width_early
88
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * width_early)
89
+ elif num_col == 2 and width_early < 2000:
90
+ img_w_new = 2400
91
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 2400)
92
+ elif num_col == 2 and width_early >= 3500:
93
+ img_w_new = 2400
94
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 2400)
95
+ elif num_col == 2 and width_early >= 2000 and width_early < 3500:
96
+ img_w_new = width_early
97
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * width_early)
98
+ elif num_col == 3 and width_early < 2000:
99
+ img_w_new = 3000
100
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 3000)
101
+ elif num_col == 3 and width_early >= 4000:
102
+ img_w_new = 3000
103
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 3000)
104
+ elif num_col == 3 and width_early >= 2000 and width_early < 4000:
105
+ img_w_new = width_early
106
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * width_early)
107
+ elif num_col == 4 and width_early < 2500:
108
+ img_w_new = 4000
109
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 4000)
110
+ elif num_col == 4 and width_early >= 5000:
111
+ img_w_new = 4000
112
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 4000)
113
+ elif num_col == 4 and width_early >= 2500 and width_early < 5000:
114
+ img_w_new = width_early
115
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * width_early)
116
+ elif num_col == 5 and width_early < 3700:
117
+ img_w_new = 5000
118
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 5000)
119
+ elif num_col == 5 and width_early >= 7000:
120
+ img_w_new = 5000
121
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 5000)
122
+ elif num_col == 5 and width_early >= 3700 and width_early < 7000:
123
+ img_w_new = width_early
124
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * width_early)
125
+ elif num_col == 6 and width_early < 4500:
126
+ img_w_new = 6500 # 5400
127
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * 6500)
128
+ else:
129
+ img_w_new = width_early
130
+ img_h_new = int(img.shape[0] / float(img.shape[1]) * width_early)
131
+ img_new = resize_image(img, img_h_new, img_w_new)
132
+ if model_name=="SBB/eynollah-main-regions":
133
+ if num_col == 1:
134
+ img_w_new = 1000
135
+ img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
136
+
137
+ elif num_col == 2:
138
+ img_w_new = 1500
139
+ img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
140
+
141
+ elif num_col == 3:
142
+ img_w_new = 2000
143
+ img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
144
+
145
+ elif num_col == 4:
146
+ img_w_new = 2500
147
+ img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
148
+ elif num_col == 5:
149
+ img_w_new = 3000
150
+ img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
151
+ else:
152
+ img_w_new = 4000
153
+ img_h_new = int(img_org.shape[0] / float(img_org.shape[1]) * img_w_new)
154
+ img_resized = resize_image(img,img_h_new, img_w_new )
155
+
156
+ img = otsu_copy_binary(img_resized)
157
+ return img
158
+
159
  def do_prediction(model_name, img):
160
  img_org = np.copy(img)
161
  model = from_pretrained_keras(model_name)
 
191
  img_width_h = img_org.shape[1]
192
 
193
  num_col_classifier = return_num_columns(img)
194
+ width_early = img.shape[1]
195
 
196
 
197
+ img = return_scaled_image(img, num_col_classifier, width_early, model_name)
198
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
 
200
 
201