形状不匹配模型InceptionResNetV2&weigts

时间:2019-05-23 14:07:36

标签: python shapes mismatch

我正在使用InceptionResNetV2进行图像分类并使用相应的权重。但是出现错误:

  

ValueError:您正在尝试将包含449层的权重文件加载到448层的模型中。

img_ht = 96
img_wid = 96
img_chnl = 3

import tensorflow as tf
from tensorflow import keras
from keras_preprocessing.image import ImageDataGenerator

train_generator = train_datagen.flow_from_directory(
    directory = "../input/cassava-disease/train/train/",
subset="training",
batch_size = 49,
seed=42,
shuffle=False,
class_mode="categorical",
target_size=(img_ht, img_wid))

valid_generator = train_datagen.flow_from_directory(
directory = "../input/cassava-disease/train/train/",
subset="validation",
batch_size=49,
seed=42,
shuffle=False,
class_mode="categorical",
target_size = (img_ht, img_wid))

from keras.applications import InceptionResNetV2 as InceptionResNetV2

base_model = keras.applications.InceptionResNetV2(input_shape=(img_ht, img_wid, 3), 
                                         include_top = False, 
                                         weights = "../input/inception/inception_resnet_v2_weights_tf_dim_ordering_tf_kernels.h5")

base_model.trainable = False
print(base_model.summary())

1 个答案:

答案 0 :(得分:0)

得到答案。这是因为-> include_top = False。

对于python和机器学习非常新