在至少一集之后使用keras顺序模型时,程序存在分段错误。
我们的程序使用顺序模型来控制乒乓球拍,以避免下降的乒乓球。下载游戏图像的每一帧,将其处理为80 * 60的阵列,然后发送给模型以执行操作(向右或向左移动一个像素)。游戏结束(一集)时,X_train数组,Y_train数组和奖励数组适合该模型。我们的错误至少在第二集结束之后发生,但有时在几集之后发生。该错误发生在keras模型计算内部的某个地方。
使用keras 2.1.6,张量流1.13.1,pygame 1.9.5。
def create_network():
model = Sequential()
model.add(Dense(units=200,input_dim=80*60, activation='relu', kernel_initializer='glorot_uniform'))
model.add(Dense(units=1, activation='sigmoid', kernel_initializer='RandomNormal'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
epochs_before_saving = 10
log_dir = './log' + datetime.now().strftime("%Y%m%d-%H%M%S") + "/"
tbCallBack = callbacks.TensorBoard(log_dir=settings.log_dir, histogram_freq=0,
write_graph=True, write_images=True)
上面的代码初始化了模型。
model.fit(x=np.vstack(sX_train), y=np.vstack(Y_train), verbose=1, sample_weight=reward_array)
以上一行在情节结束时将x_train,y_train和reward数组拟合到模型中。
172-26-86-157:ML tomhardy$ python dodge.py
pygame 1.9.5
Hello from the pygame community. https://www.pygame.org/contribute.html
Using TensorFlow backend.
WARNING:tensorflow:From /Users/tomhardy/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
2019-05-16 18:20:37.788946: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
WARNING:tensorflow:From /Users/tomhardy/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Epoch 1/1
15/15 [==============================] - 0s 22ms/step - loss: -0.8084 - acc: 0.6000
Epoch 1/1
15/15 [==============================] - 0s 286us/step - loss: -1.4546 - acc: 0.6000
Segmentation fault: 11
172-26-86-157:ML tomhardy$
在这种情况下,两段后发生了分割错误。