自动编码器和resnet v2功能

vjhs03f7  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(352)

我想从使用inception resnet v2模型提取的特征向量开始创建一个自动编码器,如下图所示:

这是我当时写的代码:

image_size = (150, 150, 3)

model = InceptionResNetV2(weights='imagenet', include_top=False, input_shape=image_size)   

for layer in model.layers:
    layer.trainable = False

feature = model.predict(x[:10])

print(feature.shape) # (10, 3, 3, 1536)

在keras中实现这一点的方法是什么?谢谢你抽出时间。

d8tt03nd

d8tt03nd1#

from tensorflow.keras.layers import Input, Dense, GlobalAveragePooling2D
from tensorflow.keras.applications import InceptionResNetV2
from tensorflow.keras.models import Model

image_size = (150, 150, 3)
model = InceptionResNetV2(include_top=False, input_shape=image_size)
for layer in model.layers:
    layer.trainable = False

inputs = Input(image_size)
x = model(inputs)
x = GlobalAveragePooling2D()(x)
x = Dense(500, activation='relu')(x)
x = Dense(2, activation='relu')(x)
x = Dense(500, activation='relu')(x)
x = Dense(1536, activation='relu')(x)
full_model = Model(inputs, x)
print(full_model.summary())

另一方面,我非常怀疑这个自动编码器是否能够处理这么小的瓶颈,所以我将它从2增加到更大的值(可能是100)。

相关问题