【发布时间】:2021-12-04 00:39:20
【问题描述】:
我正在尝试使用 R keras 将内置网络架构与自定义输出层相结合。具体来说,我想要一个最初为分类而构建的架构的回归输出。
这是我想要的一个简单示例:
inlayer <- layer_input(shape = c(75, 75, 1))
N1 <- application_inception_v3(weights = NULL,
input_tensor = inlayer,
include_top = FALSE)
outlayer <- layer_dense(units = 2, activation = 'sigmoid')
fullnet <- N1 %>% outlayer
但是,最后一行代码不起作用 - 我收到以下错误:
Error in py_call_impl(callable, dots$args, dots$keywords) :
AttributeError: 'Model' object has no attribute 'shape'
我认为部分问题在于内置网络 (N1) 是使用功能 API 定义的,因此无法使用 %>% 运算符按顺序添加额外的层。
我还尝试使用功能 API 将额外的输出层定义为单独的架构,但我找不到合并这两个模型的方法:
N2_in <- layer_input(shape = c(2048)) #note: output shape of N1
N2_out <- N2_in %>% layer_dense(units = 2, activation = 'sigmoid')
N2 <- keras_model(N2_in, N2_out)
#try to merge with pipe again:
N1 %>% N2
如果我尝试与管道运算符合并,则会出现以下错误:
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: Attempt to convert a value (<tensorflow.python.keras.engine.training.Model object at 0x7f88950ed748>) with an unsupported type (<class 'tensorflow.python.keras.engine.training.Model'>) to a Tensor.
非常感谢任何关于如何将 N1 与 outlayer 或 N2 结合使用的想法 - 并感谢您的阅读!
【问题讨论】: