在 Vision Transformer 模型的模型摘要和提取特征中出现错误

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

我正在编写用于图像特征提取的视觉转换器代码。我从这个 github 站点定义了一个 ViT 模型。

image_model = ViT(
    image_size=224,
    patch_size=32,
    num_classes=1000,
    dim=1024,
    depth=6,
    heads=16,
    mlp_dim=2048,
    dropout=0.1,
    emb_dropout=0.1
)

# Image Shape is 224x224 RGB
input_shape = (1, 3, 224, 224)
output_shape = (1, 1024)

new_input = tf.keras.Input(shape=input_shape)
new_input = tf.squeeze(new_input, axis=0)
new_input = tf.zeros(input_shape)
new_input = tf.convert_to_tensor(new_input)
print(f'Input Shape : {new_input.shape}')
hidden_layer = image_model(new_input)
^^^^^     
Here I am getting error saying: AttributeError: EagerTensor object has no attribute 'reshape'. 
        If you are looking for numpy-related methods, please run the following:
        from tensorflow.python.ops.numpy_ops import np_config
        np_config.enable_numpy_behavior()

print(f'\nOutput Shape : {hidden_layer.shape}')

image_features_extract_model = tf.keras.Model(new_input, output_shape, name="image_features_extract_model")

任何人都可以建议我如何编写代码来实现它。而这一代模型之后我在做

image_features_extract_model.summary()  <--- I want this as well

python tensorflow machine-learning deep-learning computer-vision
© www.soinside.com 2019 - 2024. All rights reserved.