Q&A
https://qiita.com/kkk3H/items/c3eb0d868170b29b0b87
上記の記事を参考にして画像データとラベルデータを作ろうとしたのですが
ValueError: could not broadcast input array from shape (75,75,3) into shape (75,75)
というエラーが出てしまいます。画像のデータがいけないのでしょうか? よろしくお願いします。
画像データはグレースケール画像ではなくRGB画像です。
もしかしたらそこがいけないのかもしれません。。。
Python 3.6.4
TensorFlow 1.3.0
NumPy 1.13.3
python
1import numpy 2from PIL import Image 3import glob 4from tensorflow.python.framework import dtypes 5from numpy.random import * 6import os 7numpy.random.seed(0) 8 9 10if __name__ == '__main__': 11 12 directory_path = '/Users/lab/data_set' 13 file_format = 'png' 14 shuffle = True 15 16 A_path = os.path.join(directory_path, 'A') 17 B_path = os.path.join(directory_path, 'B') 18 C_path = os.path.join(directory_path, 'C') 19 20 all_images = [] 21 all_labels = [] 22 23 label = 0 24 25 for path in [A_path, A_path, A_path]: 26 img_files = glob.glob(path + '/*.' + file_format) 27 28 for img_file in img_files: 29 img = numpy.array(Image.open(img_file)) 30 all_images.append(img) 31 all_labels.append(label) 32 33 label += 1 34 35 all_images = numpy.array(all_images) 36 all_labels = numpy.array(all_labels) 37 38 indices = numpy.arange(len(all_images)) 39 40 if shuffle: 41 numpy.random.shuffle(indices) 42 43 all_images = all_images[indices] 44 all_labels = all_labels[indices] 45 46 #print (len(all_labels)) 47 numpy.save('./imgs.npy', all_images) 48 numpy.save('./labels.npy', all_labels) 49
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2018/01/22 06:05
2018/01/22 06:12 編集
2018/01/30 16:53
2018/01/31 00:29