エラーが発生します:サイズ122304の配列を(52,28,28)の形に整形できません。
numpyの配列を次のように整形しようとしています:
data3 = data3.reshape((data3.shape[0], 28, 28))
ここで data3
は
[[54 68 66 ..., 83 72 58]
[63 63 63 ..., 51 51 51]
[41 45 80 ..., 44 46 81]
...,
[58 60 61 ..., 75 75 81]
[56 58 59 ..., 72 75 80]
[ 4 4 4 ..., 8 8 8]]
data3.shapeは
(52, 2352 )` です。
しかし、次のようなエラーが出続けます:
ValueError: cannot reshape array of size 122304 into shape (52,28,28)
Exception TypeError: TypeError("'NoneType' object is not callable",) in <function _remove at 0x10b6477d0> ignored
何が起きているのでしょうか?
アップデート
上記で使用している data3
を取得するためにこのようなことをしています:
def image_to_feature_vector(image, size=(28, 28)):
return cv2.resize(image, size).flatten()
data3 = np.array([image_to_feature_vector(cv2.imread(imagePath)) for imagePath in imagePaths])
imagePathsには、データセット内のすべての画像へのパスが含まれています。実際には、data3 を 784次元ベクトルのフラットリスト
に変換したいのです。
image_to_feature_vector
関数は3072次元のベクトルに変換します!
6
2
numpy行列の配列は、before(a x b x c...n) = after(a x b x c...n)となるように形を変えることができます。 が(156, 28, 28)となるように変換すればよい。
出力は以下のようになります。
まず、入力画像の要素数が、求める特徴ベクトルの要素数と一致する必要があります。
上記を満たすと仮定すると、以下のようになります: