前提・実現したいこと
1446枚のデータを使って学習を行いたいのですが、学習時のステータスバーを確認すると、データが121枚しか使用されていないように見受けられます。
なぜ1446枚のデータではなく、121枚しか学習に使われていないのか、お分かりの方がいらっしゃいましたらご教示いただけますでしょうか。
お手数をお掛けしますがどうぞよろしくお願いいたします。
発生している問題・エラーメッセージ
Epoch 1/100 121/121 [==============================] - 33s 270ms/step - loss: 0.4005 - accuracy: 0.8859 - val_loss: 1.3700 - val_accuracy: 0.4647
該当のソースコード
Python
1rom keras.models import Model 2from keras.layers import Dense, GlobalAveragePooling2D,Input,Dropout,Activation 3from keras.applications.resnet50 import ResNet50 4from keras.preprocessing.image import ImageDataGenerator 5from keras.optimizers import Adam 6from keras.callbacks import CSVLogger,EarlyStopping 7import numpy as np 8from keras import backend as K 9from keras.engine.topology import Layer 10import numpy as np 11import tensorflow as tf 12from keras.preprocessing.image import load_img, img_to_array, array_to_img 13import os 14import glob 15import cv2 16from PIL import Image 17import matplotlib.pyplot as plt 18import keras 19from keras import callbacks 20from keras.utils import to_categorical 21%matplotlib inline 22 23os.environ["CUDA_VISIBLE_DEVICES"]="0"#specify GPU 24 25image_size_width, image_size_height = (299, 299) 26 27folder = ["COVID-19_resize_train_1_2", "Viral Pneumonia_resize_train_1_2", "NORMAL_resize_train_1_2"] 28x_train = [] 29y_train = [] 30for index, name in enumerate(folder): 31 dir = "./" + name 32 files = glob.glob(dir + "/*.png") 33 for i, file in enumerate(files): 34 image = Image.open(file) 35 image = image.convert("RGB") 36 image = image.resize((image_size_width, image_size_height)) 37 data = np.asarray(image) 38 x_train.append(data) 39 y_train.append(index) 40 41x_train = np.array(x_train) 42y_train = np.array(y_train) 43print('x_train.shape', x_train.shape) 44print('y_train.shape', y_train.shape) 45#x_train.shape (1446, 299, 299, 3) 46#y_train.shape (1446,) 47 48folder = ["COVID-19_resize_train_3", "Viral Pneumonia_resize_train_3", "NORMAL_resize_train_3"] 49x_test = [] 50y_test = [] 51for index, name in enumerate(folder): 52 dir = "./" + name 53 files = glob.glob(dir + "/*.png") 54 for i, file in enumerate(files): 55 image = Image.open(file) 56 image = image.convert("RGB") 57 image = image.resize((image_size_width, image_size_height)) 58 data = np.asarray(image) 59 x_test.append(data) 60 y_test.append(index) 61 62x_test = np.array(x_test) 63y_test = np.array(y_test) 64print('x_test.shape', x_test.shape) 65print('y_test.shape', y_test.shape) 66#x_test.shape (723, 299, 299, 3) 67#y_test.shape (723,) 68 69input_shape = (299, 299, 3) 70classes = 3 71batchsize = 12 72epochs=100 73 74 75base_model=keras.applications.densenet.DenseNet201(input_shape=input_shape, 76 weights='imagenet', 77 include_top=False) 78 79c = base_model.output 80c = GlobalAveragePooling2D()(c) 81c = keras.layers.Lambda(lambda xx: 5*(xx)/K.sqrt(K.sum(xx**2)))(c) #metric learning 82c = Dense(classes, activation='softmax')(c) 83model = Model(inputs=base_model.input,outputs=c) 84 85model.summary() 86 87model.compile(loss='categorical_crossentropy', 88 optimizer=Adam(lr=0.001), 89 metrics=['accuracy']) 90 91callbacks_list = [ 92 callbacks.ModelCheckpoint( 93 filepath="model.DenseNet201.ep{epoch:02d}.h5", 94 save_weights_only=False, 95 save_best_only=True)]#False)] 96 97history = model.fit(x_train, to_categorical(y_train, classes), batch_size=batchsize, epochs=epochs, verbose=1, validation_data=(x_test, to_categorical(y_test, classes)), 98callbacks=callbacks_list) 99
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/11/14 04:44