KerasLayer vs tf.keras.applications performances

て烟熏妆下的殇ゞ 提交于 2020-02-05 03:36:41

问题


I've trained some networks with ResNetV2 50 ( https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/4 ) and it work very well for my datasets.

Then I tried tf.keras.applications.ResNet50 and accuracy is very lower than the other.

Here two models:

The first (with hub)

base_model = hub.KerasLayer('https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/4', input_shape=(IMAGE_H, IMAGE_W, 3))
base_model.trainable = False

model = tf.keras.Sequential([
  base_model ,
  Dense(num_classes, activation='softmax')
])

The second (with keras.applications)

base_model = tf.keras.applications.ResNet50V2(input_shape=(IMAGE_H, IMAGE_W, 3), include_top=False, weights='imagenet', pooling='avg')
base_model.trainable = False

model = tf.keras.Sequential([
  base_model,
  Dense(num_classes, activation='softmax')
])

The optimizer is the same (Adam), epochs, steps, dataset (train and validation), learning rate are the same as well. But the first start with a val_accuracy near 80% and end with an accuracy near 99%, the second start with 85% of val_accuracy from first to last epoch, as it's overfitting. I got the same behavior changing dataset and parameters for each model.

What am I doing wrong?

来源:https://stackoverflow.com/questions/59994205/keraslayer-vs-tf-keras-applications-performances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!