问题描述
我想归一化进入我的神经网络的输入,但是,当我以这种方式定义模型时:
df = pd.read_csv(r'C:\Users\Davide Mori\PycharmProjects\pythonProject\Dataset.csv')
print(df)
target_column = ['W_mag','W_phase']
predictors = list(set(list(df.columns)) - set(target_column))
X = df[predictors].values
Y = df[target_column].values
def get_model(n_inputs,n_outputs):
model = Sequential()
model.add(Dense(1000,input_dim= n_inputs,activation='relu'))
#model.add(Lambda(lambda x: K.l2_normalize(x,axis=1)))
model.add(Dense(1000,activation='linear',activity_regularizer=regularizers.l1(0.0001)))
model.add(Activation('relu'))
model.add(Dense(n_outputs,activation='linear'))
model.compile(optimizer="adam",loss="mean_squared_error",metrics=["mean_squared_error"])
model.summary()
return model
n_inputs,n_outputs = X.shape[1],Y.shape[1]
model = get_model(n_inputs,n_outputs)
# fit the model on all data
model.fit(X,Y,epochs=100,batch_size=1)
如何将lambda层应用于输入?注释行位置是否正确?因为如果我在其中放置lambda层,那么我正在规范第一个隐藏层已经“转换”的内容,对吗?我该如何解决这个问题?
这是我在将lambda图层放在其他所有内容之前的错误:
2020-10-12 15:08:46.036872: I
tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports
instructions that this TensorFlow binary was not compiled to use: AVX AVX2
Traceback (most recent call last):
File "<input>",line 1,in <module>
File "C:\Program Files\JetBrains\PyCharm
2020.2.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py",line 197,in runfile
pydev_imports.execfile(filename,global_vars,local_vars) # execute the
script
File "C:\Program Files\JetBrains\PyCharm
2020.2.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py",line
18,in execfile
exec(compile(contents+"\n",file,'exec'),glob,loc)
File "C:/Users/Davide Mori/PycharmProjects/pythonProject/prova_rete_sfs.py",line 60,in <module>
model = get_model(n_inputs,n_outputs)
File "C:/Users/Davide Mori/PycharmProjects/pythonProject/prova_rete_sfs.py",line 52,in get_model
model.summary()
File "C:\Users\Davide Mori\Anaconda3\envs\pythonProject\lib\site-
packages\tensorflow_core\python\keras\engine\network.py",line 1302,in
summary
raise ValueError('This model has not yet been built. '
ValueError: This model has not yet been built. Build the model first by
calling `build()` or calling `fit()` with some data,or specify an
`input_shape` argument in the first layer(s) for automatic build.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)