前提
映画ポスターを使用して、画像分類を勉強しています。
画像の特徴量の正規化を行い、各配列に入れる際にエラーが発生しました。
実現したいこと
エラーの解決
発生している問題・エラーメッセージ
C:\Users\ryota\AppData\Local\Temp\ipykernel_12096\28291439.py:19: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. x_train = np.array(x_train) / 255.0 ValueError Traceback (most recent call last) Input In [4], in <cell line: 19>() 16 x_test.append(img_data) 17 y_test.append(int(f.split("\\")[3].split("_")[0])) ---> 19 x_train = np.array(x_train) / 255.0 20 y_train = np.array(y_train) 21 x_test = np.array(x_test) / 255.0 ValueError: could not broadcast input array from shape (100,100,3) into shape (100,100)
該当のソースコード
import tensorflow as tf from tensorflow import keras import cv2 as cv import numpy as np import matplotlib.pyplot as plt import glob x_train = [] #訓練用のimage y_train = [] #訓練用のlabels x_test = [] #テスト用のimage y_test = [] #テスト用のimage for f in glob.glob(".\image\*\*\*.jpeg"): print(f.split("\\")) img_data = tf.io.read_file(f) img_data = tf.io.decode_jpeg(img_data) img_data = tf.image.resize(img_data,[100,100]) if f.split("\\")[2] == "train": x_train.append(img_data) y_train.append(int(f.split("\\")[3].split("_")[0])) elif f.split("\\")[2] =="test": x_test.append(img_data) y_test.append(int(f.split("\\")[3].split("_")[0])) x_train = np.array(x_train) / 255.0 y_train = np.array(y_train) x_test = np.array(x_test) / 255.0 y_test = np.array(y_test) print(x_train.shape) print(y_train.shape) print(x_test.shape) print(y_test.shape)
試したこと
エラー文を翻訳にかけ、それについて検索したが、解決方法が得られなかった。
正規化させる前に、振り分けられた、x_train内をのぞいてみました。
補足情報
映画ポスターのジャンルは8つあり、trainには合計854枚のデータ、testには合計16枚のデータがあります。
あなたの回答
tips
プレビュー