【发布时间】:2019-05-23 07:27:37
【问题描述】:
我在 json 文件中定义了一个模型定义,如下所示
{
"model": "Sequential",
"layers": [
{
"L1": "Conv2D(filters = '8', kernel_size=(3,3), strides=(1, 1), padding='valid', data_format='channels_last', activation='relu', use_bias=True, kernel_initializer='zeros', bias_initializer='zeros', kernel_regularizer=regularizers.l1(0.), bias_regularizer=regularizers.l1(0.), activity_regularizer=regularizers.l1(0.), kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.), input_shape=(28,28,1))",
"L2": "Conv2D(filters = '8', kernel_size=(3,3), strides=(1, 1), padding='valid', data_format='channels_last', activation='relu', use_bias=True, kernel_initializer='zeros', bias_initializer='zeros', kernel_regularizer=regularizers.l1(0.), bias_regularizer=regularizers.l1(0.), activity_regularizer=regularizers.l1(0.), kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.))",
"L3": "Flatten()",
"L4": "Dense(10, activation='softmax', use_bias=True, kernel_initializer='zeros', bias_initializer='zeros', kernel_regularizer='regularizers.l1(0.)', bias_regularizer='regularizers.l1(0.)', activity_regularizer='regularizers.l1(0.)', kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.))"
}
]
}
当我将它加载到模型中时,它会引发以下错误:
TypeError: cannot perform reduce with flexible type
为了从 json 加载模型,我有以下代码
with open('model_0.json','r') as fb:
con = json.load(fb)
print(con['layers'][0]['L1'])
model = Sequential()
model.add(eval(con['layers'][0]['L1']))
import pdb; pdb.set_trace()
model.add(eval(con['layers'][0]['L2']))
model.add(eval(con['layers'][0]['L3']))
model.add(eval(con['layers'][0]['L4']))
有人知道吗?
【问题讨论】:
标签: python tensorflow keras python-3.6