質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

4847閲覧

tensorflow版cycleganでエラーが出て困っています。

RyotaYamada

総合スコア6

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

1グッド

2クリップ

投稿2019/10/19 00:16

編集2019/10/19 03:18

前提・実現したいこと

tensorflow版cycleganで声質変換を行うAIを作ろうとしているのですが、以下のエラーコードが出て行き詰っています。

発生している問題・エラーメッセージ

[*] Reading checkpoint... [!] Load failed... Processing image: ./datasets/voice/testA\at.jpg Traceback (most recent call last): File "main.py", line 53, in <module> tf.app.run() File "C:\Users\mounf\Anaconda3\envs\cycleganvoicechangerproject\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run _sys.exit(main(argv)) File "main.py", line 50, in main else model.test(args) File "C:\Users\mounf\PycharmProjects\nets\model.py", line 252, in test sample_image = [load_test_data(sample_file, args.fine_size)] File "C:\Users\mounf\PycharmProjects\nets\utils.py", line 46, in load_test_data img = imread(image_path) File "C:\Users\mounf\PycharmProjects\nets\utils.py", line 88, in imread return _imread(path, mode='RGB').astype(np.float) File "C:\Users\mounf\Anaconda3\envs\cycleganvoicechangerproject\lib\site-packages\imageio\core\functions.py", line 260, in imread 'Invalid keyword argument "mode", ' 'perhaps you mean "pilmode"?' TypeError: Invalid keyword argument "mode", perhaps you mean "pilmode"?

該当のソースコード

python

1♯utils.py 2from __future__ import division 3import math 4import pprint 5import scipy.misc 6import numpy as np 7import copy 8try: 9 _imread = scipy.misc.imread 10except AttributeError: 11 from imageio import imread as _imread 12 13pp = pprint.PrettyPrinter() 14 15get_stddev = lambda x, k_h, k_w: 1/math.sqrt(k_w*k_h*x.get_shape()[-1]) 16 17♯new added functions for cyclegan 18class ImagePool(object): 19 def __init__(self, maxsize=50): 20 self.maxsize = maxsize 21 self.num_img = 0 22 self.images = [] 23 24 def __call__(self, image): 25 if self.maxsize <= 0: 26 return image 27 if self.num_img < self.maxsize: 28 self.images.append(image) 29 self.num_img += 1 30 return image 31 if np.random.rand() > 0.5: 32 idx = int(np.random.rand()*self.maxsize) 33 tmp1 = copy.copy(self.images[idx])[0] 34 self.images[idx][0] = image[0] 35 idx = int(np.random.rand()*self.maxsize) 36 tmp2 = copy.copy(self.images[idx])[1] 37 self.images[idx][1] = image[1] 38 return [tmp1, tmp2] 39 else: 40 return image 41 42def load_test_data(image_path, fine_size=256): 43 img = imread(image_path) 44 img = scipy.misc.imresize(img, [fine_size, fine_size]) 45 img = img/127.5 - 1 46 return img 47 48def load_train_data(image_path, load_size=286, fine_size=256, is_testing=False): 49 img_A = imread(image_path[0]) 50 img_B = imread(image_path[1]) 51 if not is_testing: 52 img_A = scipy.misc.imresize(img_A, [load_size, load_size]) 53 img_B = scipy.misc.imresize(img_B, [load_size, load_size]) 54 h1 = int(np.ceil(np.random.uniform(1e-2, load_size-fine_size))) 55 w1 = int(np.ceil(np.random.uniform(1e-2, load_size-fine_size))) 56 img_A = img_A[h1:h1+fine_size, w1:w1+fine_size] 57 img_B = img_B[h1:h1+fine_size, w1:w1+fine_size] 58 59 if np.random.random() > 0.5: 60 img_A = np.fliplr(img_A) 61 img_B = np.fliplr(img_B) 62 else: 63 img_A = scipy.misc.imresize(img_A, [fine_size, fine_size]) 64 img_B = scipy.misc.imresize(img_B, [fine_size, fine_size]) 65 66 img_A = img_A/127.5 - 1. 67 img_B = img_B/127.5 - 1. 68 69 img_AB = np.concatenate((img_A, img_B), axis=2) 70 # img_AB shape: (fine_size, fine_size, input_c_dim + output_c_dim) 71 return img_AB 72 73----------------------------- 74 75def get_image(image_path, image_size, is_crop=True, resize_w=64, is_grayscale = False): 76 return transform(imread(image_path, is_grayscale), image_size, is_crop, resize_w) 77 78def save_images(images, size, image_path): 79 return imsave(inverse_transform(images), size, image_path) 80 81def imread(path, is_grayscale = False): 82 if (is_grayscale): 83 return _imread(path, flatten=True).astype(np.float) 84 else: 85 return _imread(path, mode='RGB').astype(np.float) 86 87def merge_images(images, size): 88 return inverse_transform(images) 89 90def merge(images, size): 91 h, w = images.shape[1], images.shape[2] 92 img = np.zeros((h * size[0], w * size[1], 3)) 93 for idx, image in enumerate(images): 94 i = idx % size[1] 95 j = idx // size[1] 96 img[j*h:j*h+h, i*w:i*w+w, :] = image 97 98 return img 99 100def imsave(images, size, path): 101 return scipy.misc.imsave(path, merge(images, size)) 102 103def center_crop(x, crop_h, crop_w, 104 resize_h=64, resize_w=64): 105 if crop_w is None: 106 crop_w = crop_h 107 h, w = x.shape[:2] 108 j = int(round((h - crop_h)/2.)) 109 i = int(round((w - crop_w)/2.)) 110 return scipy.misc.imresize( 111 x[j:j+crop_h, i:i+crop_w], [resize_h, resize_w]) 112 113def transform(image, npx=64, is_crop=True, resize_w=64): 114 # npx : # of pixels width/height of image 115 if is_crop: 116 cropped_image = center_crop(image, npx, resize_w=resize_w) 117 else: 118 cropped_image = image 119 return np.array(cropped_image)/127.5 - 1. 120 121def inverse_transform(images): 122 return (images+1.)/2. 123 124 125---ここからfunction.py 126♯Images 127 128 129def imread(uri, format=None, **kwargs): 130 """ imread(uri, format=None, **kwargs) 131 132 Reads an image from the specified file. Returns a numpy array, which 133 comes with a dict of meta data at its 'meta' attribute. 134 135 Note that the image data is returned as-is, and may not always have 136 a dtype of uint8 (and thus may differ from what e.g. PIL returns). 137 138 Parameters 139 ♯---------- 140 uri : {str, pathlib.Path, bytes, file} 141 The resource to load the image from, e.g. a filename, pathlib.Path, 142 http address or file object, see the docs for more info. 143 format : str 144 The format to use to read the file. By default imageio selects 145 the appropriate for you based on the filename and its contents. 146 kwargs : ... 147 Further keyword arguments are passed to the reader. See :func:`.help` 148 to see what arguments are available for a particular format. 149 """ 150 151 if "mode" in kwargs: 152 raise TypeError( 153 'Invalid keyword argument "mode", ' 'perhaps you mean "pilmode"?' 154 ) 155 156 ♯Get reader and read first 157 reader = read(uri, format, "i", **kwargs) 158 with reader: 159 return reader.get_data(0) 160 161### 試したこと 162 163ネットで調べましたが、情報が少なく、有効な解決手段が見つかりませんでした。 164### 補足情報(FW/ツールのバージョンなど) 165現在使っている環境です。 166absl-py==0.8.1 167astor==0.8.0 168bleach==1.5.0 169certifi==2019.9.11 170gast==0.3.2 171grpcio==1.24.1 172html5lib==0.9999999 173imageio==2.6.1 174Markdown==3.1.1 175numpy==1.17.3 176Pillow==6.2.0 177protobuf==3.10.0 178scipy==1.3.1 179six==1.12.0 180tensorboard==1.8.0 181tensorflow-gpu==1.8.0 182termcolor==1.1.0 183Werkzeug==0.16.0 184wincertstore==0.2
ryuii👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ryuii

2019/10/19 01:45 編集

imageio.imreadのソースコード部分でエラーが出ているよう思われるので、このエラーログでは、imageio.imreadの第3引数の配列に、"mode"が含まれていてエラーが出ているとしか判断ができません。imageio.imread付近のエラーログとソースコードかあると解決につながりやすくなりますので、差し支えない範囲で、記載できますでしょうか。 解釈が間違えていたら、おっしゃってください。
RyotaYamada

2019/10/19 03:18

申し訳ありません。補足しました。
guest

回答1

0

ベストアンサー

imageio.imreadの第2引数のformatは、RGBはないように思われます。
おそらくそれでエラーが発生しているようです。

formatは、
以下のドキュメントを参考にしてみてください。

Imageio formats:
https://imageio.readthedocs.io/en/stable/formats.html

投稿2019/10/19 07:34

ryuii

総合スコア438

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

RyotaYamada

2019/10/20 03:55

本当にありがとうございます!
Kacakun

2022/03/22 01:01

I am also encountered this problem.Can you tell how to solve it? The website is invalid. Thanks!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問