我收到以下错误
ValueError: as_list() is not defined on an unknown TensorShape.
我的代码如下所示
# define input
X_input = Input(shape=(n_features, n_channels))
# define features extractor model
features = Lambda(
function=extract_features_lambda,
output_shape=(None,)
)(X_input)
# CNN block
X = Reshape((n_steps, n_length, n_channels))(X_input)
X = TimeDistributed(
Conv1D(filters=32, kernel_size=5, activation='relu'),
input_shape=(None, n_length, n_features)
)(X)
X = TimeDistributed(
Conv1D(filters=64, kernel_size=7, activation='relu')
)(X)
X = TimeDistributed(
Conv1D(filters=32, kernel_size=5, activation='relu')
)(X)
X = TimeDistributed(Dropout(0.5))(X)
X = TimeDistributed(MaxPooling1D(pool_size=2))(X)
X = Flatten()(X)
# merge the 2 features
X = Concatenate()([features, X])
Lambda图层包含了一个自定义的特征提取器函数。这个函数计算一些特征并返回一个numpy数组。
def extract_features(X):
features = np.zeros(29, X.shape[1])
# compute the features ...
return features.flatten()
def extract_features_lambda(X):
features = tf.py_function(
extract_features,
[X],
tf.float32
)
features.set_shape = ((None, 29*12))
return features
我做错了什么?
1条答案
按热度按时间vx6bjr1n1#
你用可以定制的自定义Fn Lamda是对的,我也是这么做的
1.使用Lamda回调,答案将如下所示,您可以在使用名称时跟踪每个层。
[〈KerasTensor:形状=(无,1,32,32,3)数据类型=浮点32(由图层“输入_1”创建)〉]
〈0x0000016DB5CC51C0处的keras.引擎.函数.函数对象〉
1.当你用同样的方法做时,你会得到同样的答案
[〈KerasTensor:形状=(无,1,32,32,3)数据类型=浮点32(由图层“输入_1”创建)〉]〈位于0x0000016DB5CC51C0的keras.引擎.函数.函数对象〉
1.使用顺序时,也可以按模型属性执行
模型= tf.角函数.模型.顺序([
输入图层(输入形状=(1,32,32,3)),...
])
您可以对数组和序列属性执行更多操作...