TensorFlowのCPU版で問題なく動いたプログラムをGPUサポート環境のTensorFlowを動かそうとするときに、一応処理は成功するのですが初期化と思われる段階で時間がかなりかかっています。
具体的に示すと、下記のログの
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0 で約5分、
I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll で20分弱かかっています。
ログ: https://pastebin.com/ckebAnmZ
環境構成は以下の通りです
Python 3.7
cuDNN 7.6.5
CUDA 10.1
TensorFlow 2.1.0
どうかよろしくお願いいたします。
コード: https://www.tensorflow.org/tutorials/images/classification?hl=ja
Python
1import tensorflow as tf 2 3from tensorflow.keras.models import Sequential 4from tensorflow.keras.layers import Dense, Conv2D, Flatten, Dropout, MaxPooling2D 5from tensorflow.keras.preprocessing.image import ImageDataGenerator 6import scipy 7 8import os 9import numpy as np 10import matplotlib.pyplot as plt 11 12_URL = 'https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip' 13path_to_zip = tf.keras.utils.get_file('cats_and_dogs.zip', origin=_URL, extract=True) 14PATH = os.path.join(os.path.dirname(path_to_zip), 'cats_and_dogs_filtered') 15 16train_dir = os.path.join(PATH, 'train') 17validation_dir = os.path.join(PATH, 'validation') 18 19train_cats_dir = os.path.join(train_dir, 'cats') # 学習用の猫画像のディレクトリ 20train_dogs_dir = os.path.join(train_dir, 'dogs') # 学習用の犬画像のディレクトリ 21validation_cats_dir = os.path.join(validation_dir, 'cats') # 検証用の猫画像のディレクトリ 22validation_dogs_dir = os.path.join(validation_dir, 'dogs') # 検証用の犬画像のディレクトリ 23 24num_cats_tr = len(os.listdir(train_cats_dir)) 25num_dogs_tr = len(os.listdir(train_dogs_dir)) 26 27num_cats_val = len(os.listdir(validation_cats_dir)) 28num_dogs_val = len(os.listdir(validation_dogs_dir)) 29 30total_train = num_cats_tr + num_dogs_tr 31total_val = num_cats_val + num_dogs_val 32 33batch_size = 128 34epochs = 15 35IMG_HEIGHT = 150 36IMG_WIDTH = 150 37 38train_image_generator = ImageDataGenerator(rescale=1./255) # 学習データのジェネレータ 39validation_image_generator = ImageDataGenerator(rescale=1./255) # 検証データのジェネレータ 40 41train_data_gen = train_image_generator.flow_from_directory(batch_size=batch_size, 42 directory=train_dir, 43 shuffle=True, 44 target_size=(IMG_HEIGHT, IMG_WIDTH), 45 class_mode='binary') 46 47val_data_gen = validation_image_generator.flow_from_directory(batch_size=batch_size, 48 directory=validation_dir, 49 target_size=(IMG_HEIGHT, IMG_WIDTH), 50 class_mode='binary') 51 52model = Sequential([ 53 Conv2D(16, 3, padding='same', activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH ,3)), 54 MaxPooling2D(), 55 Conv2D(32, 3, padding='same', activation='relu'), 56 MaxPooling2D(), 57 Conv2D(64, 3, padding='same', activation='relu'), 58 MaxPooling2D(), 59 Flatten(), 60 Dense(512, activation='relu'), 61 Dense(1, activation='sigmoid') 62]) 63 64model.compile(optimizer='adam', 65 loss='binary_crossentropy', 66 metrics=['accuracy']) 67 68model.summary() 69 70history = model.fit_generator( 71 train_data_gen, 72 steps_per_epoch=total_train // batch_size, 73 epochs=epochs, 74 validation_data=val_data_gen, 75 validation_steps=total_val // batch_size 76) 77 78acc = history.history['accuracy'] 79val_acc = history.history['val_accuracy'] 80 81loss = history.history['loss'] 82val_loss = history.history['val_loss'] 83 84epochs_range = range(epochs) 85 86plt.figure(figsize=(8, 8)) 87plt.subplot(1, 2, 1) 88plt.plot(epochs_range, acc, label='Training Accuracy') 89plt.plot(epochs_range, val_acc, label='Validation Accuracy') 90plt.legend(loc='lower right') 91plt.title('Training and Validation Accuracy') 92 93plt.subplot(1, 2, 2) 94plt.plot(epochs_range, loss, label='Training Loss') 95plt.plot(epochs_range, val_loss, label='Validation Loss') 96plt.legend(loc='upper right') 97plt.title('Training and Validation Loss') 98plt.show()
回答1件
あなたの回答
tips
プレビュー