やりたいこと
vgg16で転移学習さそうとしているのですがどのサイトを見てもこのエラーの解消ができません。
ソースコード
from keras.models import Model from keras.layers import Dense, GlobalAveragePooling2D,Input from keras.applications.vgg16 import VGG16 from keras.preprocessing.image import ImageDataGenerator import matplotlib.pyplot as plt N_CATEGORIES = 2 IMAGE_SIZE = 224 BATCH_SIZE = 5 NUM_EPOCHS = 5 0 train_data_dir = 'C:/Users/s/reserch/Cup' validation_data_dir = 'C:/Users/s/reserch/Cup' NUM_TRAINING = 30 NUM_VALIDATION = 5 input_tensor = Input(shape=(IMAGE_SIZE, IMAGE_SIZE, 3)) base_model = VGG16(weights='imagenet', include_top=False, input_tensor=input_tensor) x = base_model.output x = GlobalAveragePooling2D()(x) x = Dense(1024, activation='relu')(x) predictions = Dense(N_CATEGORIES, activation='softmax')(x) model = Model(inputs=base_model.input, outputs=predictions) # for layer in base_model.layers: for layer in base_model.layers[:15]: layer.trainable = False from keras.optimizers import SGD model.compile(optimizer=SGD(lr=0.0001, momentum=0.9), loss='categorical_crossentropy',metrics=['accuracy']) model.summary() train_datagen = ImageDataGenerator( rescale=1.0 / 255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, rotation_range=10) test_datagen = ImageDataGenerator( rescale=1.0 / 255, ) train_generator = train_datagen.flow_from_directory( train_data_dir, target_size=(IMAGE_SIZE, IMAGE_SIZE), batch_size=BATCH_SIZE, class_mode='categorical', shuffle=True ) validation_generator = test_datagen.flow_from_directory( validation_data_dir, target_size=(IMAGE_SIZE, IMAGE_SIZE), batch_size=BATCH_SIZE, class_mode='categorical', shuffle=True ) history = model.fit_generator(train_generator, steps_per_epoch=NUM_TRAINING//BATCH_SIZE, epochs=NUM_EPOCHS, verbose=1, validation_data=validation_generator, validation_steps=NUM_VALIDATION//BATCH_SIZE, ) model.save('transfer.h5') # モデルの保存
エラーメッセージ
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
やってみたこと
kerasとtensorflowのバージョンをダウンしたりアップしたのですがこのエラーが消えません。
あなたの回答
tips
プレビュー