【发布时间】:2020-09-10 09:43:38
【问题描述】:
我一直在使用具有 2 个输入的网络来评估我的国际象棋引擎的国际象棋位置。 为此,我将网络从我的 C++ 代码转换为 Keras,以便能够在 GPU 上对其进行训练。
我的模型如下所示:
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) (None, 20480) 0
__________________________________________________________________________________________________
input_2 (InputLayer) (None, 20480) 0
__________________________________________________________________________________________________
dense_1 (Dense) (None, 256) 5243136 input_1[0][0]
__________________________________________________________________________________________________
dense_2 (Dense) (None, 256) 5243136 input_2[0][0]
__________________________________________________________________________________________________
concatenate_1 (Concatenate) (None, 512) 0 dense_1[0][0]
dense_2[0][0]
__________________________________________________________________________________________________
dense_3 (Dense) (None, 32) 16416 concatenate_1[0][0]
__________________________________________________________________________________________________
dense_4 (Dense) (None, 32) 1056 dense_3[0][0]
__________________________________________________________________________________________________
dense_5 (Dense) (None, 1) 33 dense_4[0][0]
==================================================================================================
Total params: 10,503,777
Trainable params: 10,503,777
Non-trainable params: 0
由于大量的输入和大量的训练数据(大约 3 亿个位置),我在训练过程中使用了稀疏矩阵,效果很好。
我想将权重转移回我手写的 C++ 代码中,出于调试目的,我想将单个输入输入到 Keras 模型中,以将其与我的 C++ 模型进行比较。
indices =[21768,21769,21770,21771,21773,21774,21775,21788,21825,21830,21890,21893,21952,21959,22019,1288,1289,1290,1291,1292,1293,1294,1295,1345,1350,1410,1413,1472,1479,1539]
eval = -0.24
x_1 = np.zeros(half_input_size)
x_2 = np.zeros(half_input_size)
for i in indices:
if(i < half_input_size):
x_1[i] = 1
else:
x_2[i-half_input_size] = 1
print(x_1.shape)
print(x_2.shape)
print(model.predict([x_1, x_2]))
两个输入的形状似乎是:
(20480,)
(20480,)
然而 Keras 给了我以下错误:
Traceback (most recent call last):
File "A:/OneDrive/ProgrammSpeicher/CLionProjects/Koivisto/resources/networkTrainingKeras/Train.py", line 317, in <module>
print(model.predict([x_1, x_2]))
File "C:\Users\finne\.conda\envs\DeepLearning\lib\site-packages\keras\engine\training.py", line 1441, in predict
x, _, _ = self._standardize_user_data(x)
File "C:\Users\finne\.conda\envs\DeepLearning\lib\site-packages\keras\engine\training.py", line 579, in _standardize_user_data
exception_prefix='input')
File "C:\Users\finne\.conda\envs\DeepLearning\lib\site-packages\keras\engine\training_utils.py", line 145, in standardize_input_data
str(data_shape))
ValueError: Error when checking input: expected input_1 to have a shape (20480,) but got array with shape (1,)
如果有人能简单地告诉我我搞砸了什么,我很高兴!
问候 芬兰人
【问题讨论】:
-
是的,在训练期间,我在模型的输入节点处设置了 sparse=True,为此我将其更改为 sparse=True。
标签: python tensorflow machine-learning keras