我正在尝试使用功能性API来拥有一个共享层,其中只有一条路径是可训练的:
a_in = Input(x_shape)
b_in = Input(x_shape)
a_out = my_model(a_in) # I want these weights to be trainable
b_out = my_model(b_in) # I want these weights to be non-trainable (no gradient update)
y_out = my_merge(a_out, b_out)
full_model = Model(inputs=[a_in, b_in], outputs=[y_out])
full_model.compile(...)
Run Code Online (Sandbox Code Playgroud)
我不知道如何做到这一点。设置my_model可训练标志会影响两个图层。我可以用不同的可训练标记来编译2个不同的模型,但是然后我看不到如何结合2个预编译的模型来优化我的单个合并成本函数。
这与Keras可能吗?如果没有,TensorFlow是否有可能?