質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

595閲覧

Python 学習時にデータの一部しか認識されない

SuzuAya

総合スコア71

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/11/14 03:19

前提・実現したいこと

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

結論から言うと全部のデータが使われています。

そこに表示されている 121 はイテレーション回数です。
バッチサイズが batchsize = 12 なので、1446/12 = 120.5 なので、1エポックあたりのイテレーション回数は121回です。

投稿2020/11/14 03:52

tiitoi

総合スコア21956

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

SuzuAya

2020/11/14 04:44

>tiitoi様 早速のご回答誠にありがとうございます! イテレーション回数が表示されているのですね。少し前のバージョンまで、データ枚数が表示されていたのでてっきり何かミスがあるのだと思ってしまいました。ご教示いただき大変助かりました。いつもありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問