Spaces:
Runtime error
Runtime error
GIanlucaRub
commited on
Commit
•
6386ec0
1
Parent(s):
e547f95
Update app.py
Browse files
app.py
CHANGED
@@ -29,63 +29,104 @@ def double_res(input_image):
|
|
29 |
np.copyto(expanded_input_image[0:input_height, 0:input_width], input_image)
|
30 |
|
31 |
output_image = np.zeros((128*height*2, 128*width*2, 3), dtype=np.float32)
|
32 |
-
|
|
|
33 |
for i in range(height):
|
34 |
for j in range(width):
|
35 |
temp_slice = expanded_input_image[i *
|
36 |
128:(i+1)*128, j*128:(j+1)*128]/255
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
40 |
if i != 0 and j != 0 and i != height-1 and j != width-1:
|
41 |
-
# removing inner borders
|
42 |
right_slice = expanded_input_image[i *
|
43 |
128:(i+1)*128, (j+1)*128-64:(j+1)*128+64]/255
|
44 |
-
|
45 |
-
|
46 |
-
resized_right_slice = right_upsampled_slice[0][64:192, 64:192]
|
47 |
-
np.copyto(output_image[i*256+64:(i+1)*256-64,
|
48 |
-
(j+1)*256-64:(j+1)*256+64], resized_right_slice)
|
49 |
|
50 |
left_slice = expanded_input_image[i *
|
51 |
128:(i+1)*128, j*128-64:(j)*128+64]/255
|
52 |
-
|
53 |
-
|
54 |
-
resized_left_slice = left_upsampled_slice[0][64:192, 64:192]
|
55 |
-
np.copyto(output_image[i*256+64:(i+1)*256-64,
|
56 |
-
j*256-64:j*256+64], resized_left_slice)
|
57 |
|
58 |
upper_slice = expanded_input_image[(
|
59 |
i+1)*128-64:(i+1)*128+64, j*128:(j+1)*128]/255
|
60 |
-
|
61 |
-
|
62 |
-
resized_upper_slice = upper_upsampled_slice[0][64:192, 64:192]
|
63 |
-
np.copyto(output_image[(i+1)*256-64:(i+1)*256+64,
|
64 |
-
j*256+64:(j+1)*256-64], resized_upper_slice)
|
65 |
|
66 |
lower_slice = expanded_input_image[i *
|
67 |
128-64:i*128+64, j*128:(j+1)*128]/255
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
np.copyto(output_image[i*256-64:i*256+64,
|
72 |
j*256+64:(j+1)*256-64], resized_lower_slice)
|
73 |
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
lower_right_slice[np.newaxis, ...])
|
80 |
-
resized_lower_right_slice = lower_right_upsampled_slice[0][64:192, 64:192]
|
81 |
np.copyto(output_image[i*256-64:i*256+64, (j+1)
|
82 |
* 256-64:(j+1)*256+64], resized_lower_right_slice)
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
resized_lower_left_slice = lower_left_upsampled_slice[0][64:192, 64:192]
|
89 |
np.copyto(
|
90 |
output_image[i*256-64:i*256+64, j*256-64:j*256+64], resized_lower_left_slice)
|
91 |
|
|
|
29 |
np.copyto(expanded_input_image[0:input_height, 0:input_width], input_image)
|
30 |
|
31 |
output_image = np.zeros((128*height*2, 128*width*2, 3), dtype=np.float32)
|
32 |
+
|
33 |
+
to_predict = []
|
34 |
for i in range(height):
|
35 |
for j in range(width):
|
36 |
temp_slice = expanded_input_image[i *
|
37 |
128:(i+1)*128, j*128:(j+1)*128]/255
|
38 |
+
to_predict.append(temp_slice)
|
39 |
+
|
40 |
+
# removing inner borders
|
41 |
+
|
42 |
+
for i in range(height):
|
43 |
+
for j in range(width):
|
44 |
if i != 0 and j != 0 and i != height-1 and j != width-1:
|
|
|
45 |
right_slice = expanded_input_image[i *
|
46 |
128:(i+1)*128, (j+1)*128-64:(j+1)*128+64]/255
|
47 |
+
to_predict.append(right_slice)
|
48 |
+
|
|
|
|
|
|
|
49 |
|
50 |
left_slice = expanded_input_image[i *
|
51 |
128:(i+1)*128, j*128-64:(j)*128+64]/255
|
52 |
+
to_predict.append(left_slice)
|
53 |
+
|
|
|
|
|
|
|
54 |
|
55 |
upper_slice = expanded_input_image[(
|
56 |
i+1)*128-64:(i+1)*128+64, j*128:(j+1)*128]/255
|
57 |
+
to_predict.append(upper_slice)
|
58 |
+
|
|
|
|
|
|
|
59 |
|
60 |
lower_slice = expanded_input_image[i *
|
61 |
128-64:i*128+64, j*128:(j+1)*128]/255
|
62 |
+
to_predict.append(lower_slice)
|
63 |
+
# removing angles
|
64 |
+
|
65 |
+
lower_right_slice = expanded_input_image[i *
|
66 |
+
128-64:i*128+64, (j+1)*128-64:(j+1)*128+64]/255
|
67 |
+
to_predict.append(lower_right_slice)
|
68 |
+
|
69 |
+
lower_left_slice = expanded_input_image[i *
|
70 |
+
128-64:i*128+64, j*128-64:j*128+64]/255
|
71 |
+
to_predict.append(lower_left_slice)
|
72 |
+
|
73 |
+
# predicting all images at once
|
74 |
+
predicted = model.predict(np.array(to_predict))
|
75 |
+
counter = 0
|
76 |
+
for i in range(height):
|
77 |
+
for j in range(width):
|
78 |
+
np.copyto(output_image[i*256:(i+1)*256, j *
|
79 |
+
256:(j+1)*256], predicted[counter])
|
80 |
+
counter+=1
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
for i in range(height):
|
85 |
+
for j in range(width):
|
86 |
+
if i != 0 and j != 0 and i != height-1 and j != width-1:
|
87 |
+
right_upsampled_slice = predicted[counter]
|
88 |
+
counter+=1
|
89 |
+
resized_right_slice = right_upsampled_slice[64:192, 64:192]
|
90 |
+
np.copyto(output_image[i*256+64:(i+1)*256-64,
|
91 |
+
(j+1)*256-64:(j+1)*256+64], resized_right_slice)
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
left_upsampled_slice = predicted[counter]
|
97 |
+
counter+=1
|
98 |
+
resized_left_slice = left_upsampled_slice[64:192, 64:192]
|
99 |
+
np.copyto(output_image[i*256+64:(i+1)*256-64,
|
100 |
+
j*256-64:j*256+64], resized_left_slice)
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
upper_upsampled_slice = predicted[counter]
|
105 |
+
counter+=1
|
106 |
+
resized_upper_slice = upper_upsampled_slice[64:192, 64:192]
|
107 |
+
np.copyto(output_image[(i+1)*256-64:(i+1)*256+64,
|
108 |
+
j*256+64:(j+1)*256-64], resized_upper_slice)
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
lower_upsampled_slice = predicted[counter]
|
113 |
+
counter+=1
|
114 |
+
resized_lower_slice = lower_upsampled_slice[64:192, 64:192]
|
115 |
np.copyto(output_image[i*256-64:i*256+64,
|
116 |
j*256+64:(j+1)*256-64], resized_lower_slice)
|
117 |
|
118 |
|
119 |
+
|
120 |
+
lower_right_upsampled_slice = predicted[counter]
|
121 |
+
counter+=1
|
122 |
+
resized_lower_right_slice = lower_right_upsampled_slice[64:192, 64:192]
|
|
|
|
|
123 |
np.copyto(output_image[i*256-64:i*256+64, (j+1)
|
124 |
* 256-64:(j+1)*256+64], resized_lower_right_slice)
|
125 |
|
126 |
+
|
127 |
+
lower_left_upsampled_slice = predicted[counter]
|
128 |
+
counter+=1
|
129 |
+
resized_lower_left_slice = lower_left_upsampled_slice[64:192, 64:192]
|
|
|
130 |
np.copyto(
|
131 |
output_image[i*256-64:i*256+64, j*256-64:j*256+64], resized_lower_left_slice)
|
132 |
|