Spaces:
Runtime error
Runtime error
temp-9384289
commited on
Commit
·
3aaf803
1
Parent(s):
8009a95
testing
Browse files
app.py
CHANGED
|
@@ -120,6 +120,7 @@ def getModel(model):
|
|
| 120 |
print("===================")
|
| 121 |
|
| 122 |
lowest_score = 10000
|
|
|
|
| 123 |
|
| 124 |
for i in range(len(train_labels)):
|
| 125 |
# print(i)
|
|
@@ -148,43 +149,44 @@ def getModel(model):
|
|
| 148 |
if results['rmse'] < lowest_score:
|
| 149 |
|
| 150 |
lowest_score = results['rmse']
|
|
|
|
| 151 |
|
| 152 |
-
image1 = np.array(Image.open(file_path + 'real_deal.png'))
|
| 153 |
-
image2 = np.array(Image.open(file_path + 'generated_image.png'))
|
| 154 |
-
img1 = torch.from_numpy(image1).float().unsqueeze(0).unsqueeze(0)/255.0
|
| 155 |
-
img2 = torch.from_numpy(image2).float().unsqueeze(0).unsqueeze(0)/255.0
|
| 156 |
-
img1 = Variable( img1, requires_grad=False)
|
| 157 |
-
img2 = Variable( img2, requires_grad=True)
|
| 158 |
-
ssim_score = ssim(img1, img2).item()
|
| 159 |
|
| 160 |
-
# sys.exit()
|
| 161 |
-
# l2 = distance.euclidean(image1, image2)
|
| 162 |
|
| 163 |
-
low_score_log += 'rmse score:' + str(lowest_score) + "\n"
|
| 164 |
-
low_score_log += 'ssim score:' + str(ssim_score) + "\n"
|
| 165 |
-
low_score_log += 'found when:' + str(round( ((i/len(train_labels)) * 100),2 )) + '%' + "\n"
|
| 166 |
|
| 167 |
-
low_score_log += "---------\n"
|
| 168 |
|
| 169 |
-
print(lowest_score, ssim_score, str(round( ((i/len(train_labels)) * 100),2 )) + '%')
|
| 170 |
|
| 171 |
-
fig = plt.figure(figsize=(1, 1))
|
| 172 |
-
plt.subplot(1, 1, 0+1)
|
| 173 |
-
plt.imshow(to_check, cmap='gray')
|
| 174 |
-
plt.axis('off')
|
| 175 |
-
plt.savefig(file_path+str(i) + "--" + str(lowest_score) + '---most_close.png')
|
| 176 |
-
plt.close()
|
| 177 |
|
| 178 |
|
| 179 |
-
f = open(file_path + "score_log.txt", "w+")
|
| 180 |
-
f.write(low_score_log)
|
| 181 |
-
f.close()
|
| 182 |
|
| 183 |
print("Done!")
|
| 184 |
|
| 185 |
|
| 186 |
############################################ return image that you just generated
|
| 187 |
-
return image
|
| 188 |
|
| 189 |
|
| 190 |
import gradio as gr
|
|
|
|
| 120 |
print("===================")
|
| 121 |
|
| 122 |
lowest_score = 10000
|
| 123 |
+
lowest_image = None
|
| 124 |
|
| 125 |
for i in range(len(train_labels)):
|
| 126 |
# print(i)
|
|
|
|
| 149 |
if results['rmse'] < lowest_score:
|
| 150 |
|
| 151 |
lowest_score = results['rmse']
|
| 152 |
+
lowest_image = to_check
|
| 153 |
|
| 154 |
+
# image1 = np.array(Image.open(file_path + 'real_deal.png'))
|
| 155 |
+
# image2 = np.array(Image.open(file_path + 'generated_image.png'))
|
| 156 |
+
# img1 = torch.from_numpy(image1).float().unsqueeze(0).unsqueeze(0)/255.0
|
| 157 |
+
# img2 = torch.from_numpy(image2).float().unsqueeze(0).unsqueeze(0)/255.0
|
| 158 |
+
# img1 = Variable( img1, requires_grad=False)
|
| 159 |
+
# img2 = Variable( img2, requires_grad=True)
|
| 160 |
+
# ssim_score = ssim(img1, img2).item()
|
| 161 |
|
| 162 |
+
# # sys.exit()
|
| 163 |
+
# # l2 = distance.euclidean(image1, image2)
|
| 164 |
|
| 165 |
+
# low_score_log += 'rmse score:' + str(lowest_score) + "\n"
|
| 166 |
+
# low_score_log += 'ssim score:' + str(ssim_score) + "\n"
|
| 167 |
+
# low_score_log += 'found when:' + str(round( ((i/len(train_labels)) * 100),2 )) + '%' + "\n"
|
| 168 |
|
| 169 |
+
# low_score_log += "---------\n"
|
| 170 |
|
| 171 |
+
# print(lowest_score, ssim_score, str(round( ((i/len(train_labels)) * 100),2 )) + '%')
|
| 172 |
|
| 173 |
+
# fig = plt.figure(figsize=(1, 1))
|
| 174 |
+
# plt.subplot(1, 1, 0+1)
|
| 175 |
+
# plt.imshow(to_check, cmap='gray')
|
| 176 |
+
# plt.axis('off')
|
| 177 |
+
# plt.savefig(file_path+str(i) + "--" + str(lowest_score) + '---most_close.png')
|
| 178 |
+
# plt.close()
|
| 179 |
|
| 180 |
|
| 181 |
+
# f = open(file_path + "score_log.txt", "w+")
|
| 182 |
+
# f.write(low_score_log)
|
| 183 |
+
# f.close()
|
| 184 |
|
| 185 |
print("Done!")
|
| 186 |
|
| 187 |
|
| 188 |
############################################ return image that you just generated
|
| 189 |
+
return (image, lowest_image)
|
| 190 |
|
| 191 |
|
| 192 |
import gradio as gr
|