fchollet / deep-learning-models

Keras code and weights files for popular deep learning models.
MIT License
7.32k stars 2.46k forks source link

Strange behavior when add pre-trained InceptionResNetV2 as conv_base #75

Open yunxiaoshi opened 7 years ago

yunxiaoshi commented 7 years ago

Hello everyone

I encountered a strange problem as I was trying to add pre-trained InceptionResNetV2 as my conv_base. Concretely, when I did

import tensorflow as tf
from keras import models
from keras import layers
from keras.applications import inception_resnet_v2

with tf.device('/cpu:0'):
    conv_base = inception_resnet_v2.InceptionResNetV2(weights='imagenet', include_top=False, input_shape=some_shape)
    model = models.Sequential()
    model.add(layers.GlobalAveragePooling2D())
    model.add(layers.Dense(num_classes, activation='softmax'))
    print(model.summary())

It went stuck and took forever. But when I did

with tf.device('/cpu:0'):
    conv_base = inception_resnet_v2.InceptionResNetV2(weights='imagenet', include_top=False, input_shape=some_shape)
    print(conv_base.summary())

It took a few seconds and everything's fine. I'm on TF==1.4.0 and Keras==2.0.9 and I made sure both the CPU and GPU were idle when I was doing this. Has anyone encountered the same problem?

@fchollet Father of Keras, please help!