【问题标题】:CNN Model overfitting and not learning correctly from OpenCV sequences when learning games学习游戏时 CNN 模型过度拟合且无法从 OpenCV 序列中正确学习
【发布时间】:2019-04-06 16:47:52
【问题描述】:

我正在尝试启动并运行卷积神经网络,以便能够玩旧的 NES Ice Climbers。现在我已经使用 OpenCV 来捕获屏幕的输入,输出是攀冰者的动作,例如向左 - 向右行走或跳跃。我遇到的问题是经过训练的模型实际上并没有正确学习,或者在我验证它时它已经过拟合了。

我尝试通过排除跳转命令来降低输出。我尝试了不同的批量大小、时期和不同的测试数据。我也尝试过更改优化器和维度,但没有产生重大影响。

这是我捕获屏幕并使用该数据训练我的模型时的代码。我的训练数据是 900 个连续的屏幕截图,其中包含我播放的相应输入。我从训练数据中保存了大约 10k 个序列。

def screen_record():
   global last_time
   printscreen =  np.array(ImageGrab.grab(bbox=(0,130,800,640)))
   last_time = time.time()
   processed = greycode(printscreen)
   processed = cv2.resize(processed, (80, 60))
   cv2.imshow('AIBOX', processed)
   cv2.moveWindow("AIBOX", 500, 150);

   #training.append([processed, check_input()])
   processed = np.array(processed).reshape(-1, 80, 60, 1)
   result = AI.predict(processed, batch_size=1)
   print (result)
   AI_Control_Access(result)

def greycode(screen):
   greymap = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY) 
   greymap = cv2.Canny(greymap, threshold1=200, threshold2=300) 
   return  greymap    

def network_train():
   train_data = np.load('ICE_Train5.npy')
   train = train_data[::7]
   test = train_data[-3::]

   x_train = np.array([i[0] for i in train]).reshape(-1,80,60,1)
   x_test = np.array([i[0] for i in test]).reshape(-1,80,60,1)
   y_train = np.asarray([i[1] for i in train])
   y_test = np.asarray([i[1] for i in test])

   model = Sequential()
   model.add(Convolution2D(32, (3, 3), activation='relu', input_shape=(80, 60, 1)))
   model.add(Convolution2D(16, (5, 5), activation='relu', strides=4))
   model.add(MaxPooling2D(pool_size=(2, 2)))
   model.add(Dropout(0.25))
   model.add(Flatten())
   model.add(Dense(128, activation='relu'))
   model.add(Dropout(0.5))
   model.add(Dense(2, activation='softmax'))
   sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
   model.compile(loss='categorical_crossentropy', optimizer='sgd')
   model.fit(x_train, y_train,batch_size=450,epochs=50,verbose=1,callbacks=None,validation_split=0,validation_data=None,shuffle=False,
           class_weight=None,sample_weight=None,initial_epoch=0,steps_per_epoch=None,validation_steps=None)

当我针对测试数据运行它以进行验证时,我可以获得的最高值约为 16%,但即使我使用该模型实际玩游戏时,它总是预测按下相同的按钮,所以我认为这要么是由于过度模型的拟合或模型根本没有学习,但由于这是我第一次使用卷积网络,我不确定如何调整网络以更好地响应训练。

【问题讨论】:

    标签: python opencv keras conv-neural-network cntk


    【解决方案1】:

    一般设置听起来更像是强化学习的良好环境。

    如果您想坚持使用监督学习设置,您应该首先检查您的不同班级是否有相同数量的训练示例。如果是这种情况,您可以尝试学习率、更多正则化(dropout)、网络架构等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-17
      • 2020-07-17
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多