質問編集履歴

3

2018/12/05 12:53

投稿

kktmkmmk
kktmkmmk

スコア10

test CHANGED
File without changes
test CHANGED
File without changes

2

タイトル

2018/12/05 12:53

投稿

kktmkmmk
kktmkmmk

スコア10

test CHANGED
@@ -1 +1 @@
1
- 保存したモデルの再利用時のエラーについて
1
+ [pycharm]保存したモデルの再利用時のエラーについて[tensorflow]
test CHANGED
File without changes

1

コードの修正

2018/12/03 10:49

投稿

kktmkmmk
kktmkmmk

スコア10

test CHANGED
File without changes
test CHANGED
@@ -28,15 +28,13 @@
28
28
 
29
29
 
30
30
 
31
- # Load development/test data:
31
+
32
32
 
33
33
  dir_dev = r"data"
34
34
 
35
35
  n_im_dev = 90 # How many images to load
36
36
 
37
- # Load images and create motion-corrupted frequency space
37
+
38
-
39
- # No normalization or rotations:
40
38
 
41
39
  X_dev, Y_dev = load_images_from_folder( # Load images for evaluating model
42
40
 
@@ -180,8 +178,6 @@
180
178
 
181
179
  reuse=tf.AUTO_REUSE,
182
180
 
183
- #reuse=False,
184
-
185
181
  variables_collections=None,
186
182
 
187
183
  outputs_collections=None,
@@ -214,8 +210,6 @@
214
210
 
215
211
  reuse=tf.AUTO_REUSE,
216
212
 
217
- # reuse=False,
218
-
219
213
  variables_collections=None,
220
214
 
221
215
  outputs_collections=None,
@@ -226,13 +220,13 @@
226
220
 
227
221
 
228
222
 
229
- # Reshape output from FC layers into array of size (n_im, n_H0, n_W0, 1):
223
+
230
224
 
231
225
  FC_M = tf.reshape(FC2, [tf.shape(x)[0], tf.shape(x)[1], tf.shape(x)[2], 1])
232
226
 
233
227
 
234
228
 
235
- # Retrieve the parameters from the dictionary "parameters":
229
+
236
230
 
237
231
  W1 = parameters['W1']
238
232
 
@@ -242,33 +236,29 @@
242
236
 
243
237
 
244
238
 
245
- # CONV2D: filters W1, stride of 1, padding 'SAME'
239
+
246
-
247
- # Input size (n_im, n_H0, n_W0, 1), output size (n_im, n_H0, n_W0, 64)
248
240
 
249
241
  Z1 = tf.nn.conv2d(FC_M, W1, strides=[1, 1, 1, 1], padding='SAME')
250
242
 
251
- # RELU
243
+
252
244
 
253
245
  CONV1 = tf.nn.relu(Z1)
254
246
 
255
247
 
256
248
 
257
- # CONV2D: filters W2, stride 1, padding 'SAME'
249
+
258
-
259
- # Input size (n_im, n_H0, n_W0, 64), output size (n_im, n_H0, n_W0, 64)
260
250
 
261
251
  Z2 = tf.nn.conv2d(CONV1, W2, strides=[1, 1, 1, 1], padding='SAME')
262
252
 
263
- # RELU
253
+
264
254
 
265
255
  CONV2 = tf.nn.relu(Z2)
266
256
 
267
257
 
268
258
 
269
- # DE-CONV2D: filters W3, stride 1, padding 'SAME'
259
+
270
-
271
- # Input size (n_im, n_H0, n_W0, 64), output size (n_im, n_H0, n_W0, 1)
260
+
261
+
272
262
 
273
263
  batch_size = tf.shape(x)[0]
274
264
 
@@ -306,31 +296,31 @@
306
296
 
307
297
 
308
298
 
309
- # Create Placeholders
299
+
310
300
 
311
301
  X, Y = create_placeholders(n_H0, n_W0)
312
302
 
313
303
 
314
304
 
315
- # Initialize parameters
305
+
316
306
 
317
307
  parameters = initialize_parameters()
318
308
 
319
309
 
320
310
 
321
- # Build the forward propagation in the tf graph
311
+
322
312
 
323
313
  forward_propagation(X, parameters)
324
314
 
325
315
 
326
316
 
327
- # Add ops to save and restore all the variables
317
+
328
318
 
329
319
  saver = tf.train.Saver()
330
320
 
331
321
 
332
322
 
333
- # Start the session to compute the tf graph
323
+
334
324
 
335
325
  with tf.Session() as sess:
336
326
 
@@ -356,8 +346,6 @@
356
346
 
357
347
 
358
348
 
359
- # Reconstruct the image using trained model
360
-
361
349
  _, Y_recon = model(X_dev)
362
350
 
363
351
  print('Y_recon.shape = ', Y_recon.shape)
@@ -368,9 +356,7 @@
368
356
 
369
357
 
370
358
 
371
- # Visualize the images, their reconstruction using iFFT and using trained model
359
+
372
-
373
- # 4 images to visualize:
374
360
 
375
361
  im1 = 32
376
362
 
@@ -382,15 +368,13 @@
382
368
 
383
369
 
384
370
 
385
- # iFFT back to image from corrupted frequency space
371
+
386
-
387
- # Complex image from real and imaginary part
388
372
 
389
373
  X_dev_compl = X_dev[:, :, :, 0] + X_dev[:, :, :, 1] * 1j
390
374
 
391
375
 
392
376
 
393
- #iFFT
377
+
394
378
 
395
379
  X_iFFT0 = np.fft.ifft2(X_dev_compl[im1, :, :])
396
380
 
@@ -402,7 +386,7 @@
402
386
 
403
387
 
404
388
 
405
- # Magnitude of complex image
389
+
406
390
 
407
391
  X_iFFT_M1 = np.sqrt(np.power(X_iFFT0.real, 2)
408
392
 
@@ -422,10 +406,6 @@
422
406
 
423
407
 
424
408
 
425
- # SHOW
426
-
427
- # Show Y - input images
428
-
429
409
  plt.subplot(341), plt.imshow(Y_dev[im1, :, :], cmap='gray')
430
410
 
431
411
  plt.title('Y_dev1'), plt.xticks([]), plt.yticks([])
@@ -444,7 +424,7 @@
444
424
 
445
425
 
446
426
 
447
- # Show images reconstructed using iFFT
427
+
448
428
 
449
429
  plt.subplot(345), plt.imshow(X_iFFT_M1, cmap='gray')
450
430
 
@@ -464,7 +444,7 @@
464
444
 
465
445
 
466
446
 
467
- # Show images reconstructed using model
447
+
468
448
 
469
449
  plt.subplot(349), plt.imshow(Y_recon[im1, :, :], cmap='gray')
470
450