DCGANで画像の自動生成を行う際に「'numpy.ndarray' object is not callable」というエラーが発生します。コードは下のものです。GoogleColaboratoryで実行しています。
python
1# 本物データをGeneratorで生成したデータのスケールを-1~1で揃える 2 3def scale(x, feature_ranges=(-1, 1)): 4 # 0~1に変換 5 x = ((x - x.min()) / (255 - x.min())) 6 7 # -1~1に変換 8 min, max = feature_ranges 9 x = x * (max - min) + min 10 return x 11 12class Dataset: 13 # val_fracでテストデータを学習中と学習後用に分離する 14 # スケール関数は上のものを使うためscale_func=None 15 def __init__(self, shuffle= False, scale_func=None): 16 self.test_x, self.valid_x = test_img2, valid_img2 17 self.test_y, self.valid_y = test_index, valid_index 18 self.train_x, self.train_y = train_img2, train_index 19 20 if scale_func is None: 21 self.scaler = scale 22 else: 23 self.scaler = scale_func 24 self.shuffle = shuffle 25 26 # ミニバッチ生成の定義 27 def batches(self, batch_size): 28 if (self.shuffle).any(): 29 idx = np.arange(len(dataset.train_x)) 30 np.random.shuffle(idx) 31 self.train_x = self.train_x[idx] 32 self.train_y = self.train_y[idx] 33 34 n_batches = len(self.train_y) // batch_size 35 for ii in range(0, len(self.train_y), batch_size): 36 x = self.train_x[ii:ii+batch_size] 37 y = self.train_y[ii:ii+batch_size] 38 39 yield self.scaler(x), y 40 41 (中略) 42 43# トレーニングの実行 44 45dataset = Dataset(train_img2, test_img2) 46 47losses, samples = train(net, dataset, epochs, batch_size, figsize=(10, 5))
これを実行すると次のようなエラーが出ます。
python
1--------------------------------------------------------------------------- 2TypeError Traceback (most recent call last) 3<ipython-input-16-79c936bb63bd> in <module>() 4 2 dataset = Dataset(train_img2, test_img2) 5 3 6----> 4 losses, samples = train(net, dataset, epochs, batch_size, figsize=(10, 5)) 7 81 frames 9<ipython-input-14-07c181927757> in train(net, dataset, epochs, batch_size, print_every, show_every, figsize) 10 14 for e in range(epochs): 11 15 # バッチで取り出してパラメータの更新を行う 12---> 16 for x, y in dataset.batches(batch_size): 13 17 # for文のたびにstep数を1増加 14 18 steps += 1 15 16<ipython-input-6-f57b4d686916> in batches(self, batch_size) 17 26 y = self.train_y[ii:ii+batch_size] 18 27 19---> 28 yield self.scaler(x), y 20 21TypeError: 'numpy.ndarray' object is not callable
定義したself.scaler
を使ってxとyを返したいのですが,このようなエラーが出ます。
どのように修正すればこのエラーを解決できるのでしょうか?
あなたの回答
tips
プレビュー