質問編集履歴
1
補足しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,22 +3,193 @@
|
|
3
3
|
### 発生している問題・エラーメッセージ
|
4
4
|
|
5
5
|
```
|
6
|
+
[*] Reading checkpoint...
|
7
|
+
[!] Load failed...
|
8
|
+
Processing image: ./datasets/voice/testA\at.jpg
|
9
|
+
Traceback (most recent call last):
|
10
|
+
File "main.py", line 53, in <module>
|
11
|
+
tf.app.run()
|
12
|
+
File "C:\Users\mounf\Anaconda3\envs\cycleganvoicechangerproject\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run
|
13
|
+
_sys.exit(main(argv))
|
14
|
+
File "main.py", line 50, in main
|
15
|
+
else model.test(args)
|
16
|
+
File "C:\Users\mounf\PycharmProjects\nets\model.py", line 252, in test
|
17
|
+
sample_image = [load_test_data(sample_file, args.fine_size)]
|
18
|
+
File "C:\Users\mounf\PycharmProjects\nets\utils.py", line 46, in load_test_data
|
19
|
+
img = imread(image_path)
|
20
|
+
File "C:\Users\mounf\PycharmProjects\nets\utils.py", line 88, in imread
|
21
|
+
return _imread(path, mode='RGB').astype(np.float)
|
6
22
|
File "C:\Users\mounf\Anaconda3\envs\cycleganvoicechangerproject\lib\site-packages\imageio\core\functions.py", line 260, in imread
|
7
23
|
'Invalid keyword argument "mode", ' 'perhaps you mean "pilmode"?'
|
8
24
|
TypeError: Invalid keyword argument "mode", perhaps you mean "pilmode"?
|
9
25
|
|
10
26
|
|
27
|
+
|
11
28
|
```
|
12
29
|
|
13
30
|
### 該当のソースコード
|
14
31
|
|
15
32
|
```python
|
33
|
+
♯utils.py
|
34
|
+
from __future__ import division
|
35
|
+
import math
|
36
|
+
import pprint
|
37
|
+
import scipy.misc
|
38
|
+
import numpy as np
|
39
|
+
import copy
|
40
|
+
try:
|
41
|
+
_imread = scipy.misc.imread
|
42
|
+
except AttributeError:
|
43
|
+
from imageio import imread as _imread
|
44
|
+
|
45
|
+
pp = pprint.PrettyPrinter()
|
46
|
+
|
47
|
+
get_stddev = lambda x, k_h, k_w: 1/math.sqrt(k_w*k_h*x.get_shape()[-1])
|
48
|
+
|
49
|
+
♯new added functions for cyclegan
|
50
|
+
class ImagePool(object):
|
51
|
+
def __init__(self, maxsize=50):
|
52
|
+
self.maxsize = maxsize
|
53
|
+
self.num_img = 0
|
54
|
+
self.images = []
|
55
|
+
|
56
|
+
def __call__(self, image):
|
57
|
+
if self.maxsize <= 0:
|
58
|
+
return image
|
59
|
+
if self.num_img < self.maxsize:
|
60
|
+
self.images.append(image)
|
61
|
+
self.num_img += 1
|
62
|
+
return image
|
63
|
+
if np.random.rand() > 0.5:
|
64
|
+
idx = int(np.random.rand()*self.maxsize)
|
65
|
+
tmp1 = copy.copy(self.images[idx])[0]
|
66
|
+
self.images[idx][0] = image[0]
|
67
|
+
idx = int(np.random.rand()*self.maxsize)
|
68
|
+
tmp2 = copy.copy(self.images[idx])[1]
|
69
|
+
self.images[idx][1] = image[1]
|
70
|
+
return [tmp1, tmp2]
|
71
|
+
else:
|
72
|
+
return image
|
73
|
+
|
74
|
+
def load_test_data(image_path, fine_size=256):
|
75
|
+
img = imread(image_path)
|
76
|
+
img = scipy.misc.imresize(img, [fine_size, fine_size])
|
77
|
+
img = img/127.5 - 1
|
78
|
+
return img
|
79
|
+
|
80
|
+
def load_train_data(image_path, load_size=286, fine_size=256, is_testing=False):
|
81
|
+
img_A = imread(image_path[0])
|
82
|
+
img_B = imread(image_path[1])
|
83
|
+
if not is_testing:
|
84
|
+
img_A = scipy.misc.imresize(img_A, [load_size, load_size])
|
85
|
+
img_B = scipy.misc.imresize(img_B, [load_size, load_size])
|
86
|
+
h1 = int(np.ceil(np.random.uniform(1e-2, load_size-fine_size)))
|
87
|
+
w1 = int(np.ceil(np.random.uniform(1e-2, load_size-fine_size)))
|
88
|
+
img_A = img_A[h1:h1+fine_size, w1:w1+fine_size]
|
89
|
+
img_B = img_B[h1:h1+fine_size, w1:w1+fine_size]
|
90
|
+
|
91
|
+
if np.random.random() > 0.5:
|
92
|
+
img_A = np.fliplr(img_A)
|
93
|
+
img_B = np.fliplr(img_B)
|
94
|
+
else:
|
95
|
+
img_A = scipy.misc.imresize(img_A, [fine_size, fine_size])
|
96
|
+
img_B = scipy.misc.imresize(img_B, [fine_size, fine_size])
|
97
|
+
|
98
|
+
img_A = img_A/127.5 - 1.
|
99
|
+
img_B = img_B/127.5 - 1.
|
100
|
+
|
101
|
+
img_AB = np.concatenate((img_A, img_B), axis=2)
|
102
|
+
# img_AB shape: (fine_size, fine_size, input_c_dim + output_c_dim)
|
103
|
+
return img_AB
|
104
|
+
|
105
|
+
-----------------------------
|
106
|
+
|
107
|
+
def get_image(image_path, image_size, is_crop=True, resize_w=64, is_grayscale = False):
|
108
|
+
return transform(imread(image_path, is_grayscale), image_size, is_crop, resize_w)
|
109
|
+
|
110
|
+
def save_images(images, size, image_path):
|
111
|
+
return imsave(inverse_transform(images), size, image_path)
|
112
|
+
|
113
|
+
def imread(path, is_grayscale = False):
|
114
|
+
if (is_grayscale):
|
115
|
+
return _imread(path, flatten=True).astype(np.float)
|
116
|
+
else:
|
117
|
+
return _imread(path, mode='RGB').astype(np.float)
|
118
|
+
|
119
|
+
def merge_images(images, size):
|
120
|
+
return inverse_transform(images)
|
121
|
+
|
122
|
+
def merge(images, size):
|
123
|
+
h, w = images.shape[1], images.shape[2]
|
124
|
+
img = np.zeros((h * size[0], w * size[1], 3))
|
125
|
+
for idx, image in enumerate(images):
|
126
|
+
i = idx % size[1]
|
127
|
+
j = idx // size[1]
|
128
|
+
img[j*h:j*h+h, i*w:i*w+w, :] = image
|
129
|
+
|
130
|
+
return img
|
131
|
+
|
132
|
+
def imsave(images, size, path):
|
133
|
+
return scipy.misc.imsave(path, merge(images, size))
|
134
|
+
|
135
|
+
def center_crop(x, crop_h, crop_w,
|
136
|
+
resize_h=64, resize_w=64):
|
137
|
+
if crop_w is None:
|
138
|
+
crop_w = crop_h
|
139
|
+
h, w = x.shape[:2]
|
140
|
+
j = int(round((h - crop_h)/2.))
|
141
|
+
i = int(round((w - crop_w)/2.))
|
142
|
+
return scipy.misc.imresize(
|
143
|
+
x[j:j+crop_h, i:i+crop_w], [resize_h, resize_w])
|
144
|
+
|
145
|
+
def transform(image, npx=64, is_crop=True, resize_w=64):
|
146
|
+
# npx : # of pixels width/height of image
|
147
|
+
if is_crop:
|
148
|
+
cropped_image = center_crop(image, npx, resize_w=resize_w)
|
149
|
+
else:
|
150
|
+
cropped_image = image
|
151
|
+
return np.array(cropped_image)/127.5 - 1.
|
152
|
+
|
153
|
+
def inverse_transform(images):
|
154
|
+
return (images+1.)/2.
|
155
|
+
|
156
|
+
|
157
|
+
♯---ここからfunction.py
|
158
|
+
♯Images
|
159
|
+
|
160
|
+
|
161
|
+
def imread(uri, format=None, **kwargs):
|
162
|
+
""" imread(uri, format=None, **kwargs)
|
163
|
+
|
164
|
+
Reads an image from the specified file. Returns a numpy array, which
|
165
|
+
comes with a dict of meta data at its 'meta' attribute.
|
166
|
+
|
167
|
+
Note that the image data is returned as-is, and may not always have
|
168
|
+
a dtype of uint8 (and thus may differ from what e.g. PIL returns).
|
169
|
+
|
170
|
+
Parameters
|
171
|
+
♯----------
|
172
|
+
uri : {str, pathlib.Path, bytes, file}
|
173
|
+
The resource to load the image from, e.g. a filename, pathlib.Path,
|
174
|
+
http address or file object, see the docs for more info.
|
175
|
+
format : str
|
176
|
+
The format to use to read the file. By default imageio selects
|
177
|
+
the appropriate for you based on the filename and its contents.
|
178
|
+
kwargs : ...
|
179
|
+
Further keyword arguments are passed to the reader. See :func:`.help`
|
180
|
+
to see what arguments are available for a particular format.
|
181
|
+
"""
|
182
|
+
|
16
183
|
if "mode" in kwargs:
|
17
184
|
raise TypeError(
|
18
185
|
'Invalid keyword argument "mode", ' 'perhaps you mean "pilmode"?'
|
19
186
|
)
|
20
|
-
```
|
21
187
|
|
188
|
+
♯Get reader and read first
|
189
|
+
reader = read(uri, format, "i", **kwargs)
|
190
|
+
with reader:
|
191
|
+
return reader.get_data(0)
|
192
|
+
|
22
193
|
### 試したこと
|
23
194
|
|
24
195
|
ネットで調べましたが、情報が少なく、有効な解決手段が見つかりませんでした。
|