预期的 TensorFlowOpLayer 但 TFOpLambda 返回了

问题描述 投票:0回答:1

我正在使用功能 API 创建一个 keras 模型。然而,并非所有中间层都是我期望的类型。具体来说,就是代码:

def alpaca_model(image_shape=IMG_SIZE, data_augmentation=data_augmenter()):

input_shape = image_shape + (3,)

### START CODE HERE

base_model = tf.keras.applications.MobileNetV2(input_shape=input_shape,
                                               include_top=False, # <== Important!!!!
                                               weights='imagenet') # From imageNet

# freeze the base model by making it non trainable
base_model.trainable = False 

# create the input layer (Same as the imageNetv2 input size)
inputs = tf.keras.Input(shape=input_shape) # create the input node of the graph

# apply data augmentation to the inputs
x = data_augmentation(inputs)# this applies Sequential API layer to the Input callable object

# data preprocessing using the same weights the model was trained on
x = preprocess_input(x)

# set training to False to avoid keeping track of statistics in the batch norm layer
x = base_model(x,training=False)

# add the new Binary classification layers
x = tf.keras.layers.GlobalAveragePooling2D()(x)  # compute the mean in each channel
# include dropout with probability of 0.2 to avoid overfitting
x = tf.keras.layers.Dropout(rate=0.2)(x)
    
# use a prediction layer with one neuron (as a binary classifier only needs one)
outputs = tf.keras.layers.Dense(units=1)(x)
    
model = tf.keras.Model(inputs, outputs)

return model

问题是操作

preprocess_input(x)
base_model(x)
返回一个类型为 TFOpLambda 且形状为 (None, 160, 160, 3) 的层,它是一个元组,而我期望类型为 TensorFlowOpLayer 的层并且形状 [(无, 160, 160, 3)].

您对问题所在有任何提示吗?

python tensorflow keras deep-learning
1个回答
0
投票

你能解决这个问题吗?

© www.soinside.com 2019 - 2024. All rights reserved.