0
我想創建一個能夠自己玩賽車遊戲的CNN。 我已經訓練了模型30.000樣,我的特點(x_test)的框架和我的標籤(y_test)是世界艾滋病鍵(獨熱編碼) 但我的模型預測這個,而不是預測 3個概率:神經網絡模型預測意想不到的結果
[ 1. 0. 0.]
[ 1. 0. 0.]
[ 1. 0. 0.]
[ 1. 0. 0.]
[ 1. 0. 0.]
[ 1. 0. 0.]
問題在我的模型結構中,還是我需要更大的數據集?
我的代碼是:
培訓
classifier = create_model() train_data=np.load('data1/final_data.npy') for i in range(52): file_name = 'data2/training_data-{}.npy'.format(i) train_data_2=np.load(file_name) train_data=np.concatenate((train_data,train_data_2)) shuffle(train_data) x=train_data[:,0] y=train_data[:,1] train_data=[] x=x.tolist() x=np.array(x) y=y.tolist() y=np.array(y) classifier.fit(x,y, epochs=5, batch_size=32) classifier.save('/output/model.model')
型號
def create_model(): classifier = Sequential() classifier.add(Conv2D(96,(3,3),input_shape=(120,160,3),activation='relu')) classifier.add(MaxPooling2D(pool_size=(2,2))) classifier.add(Conv2D(256,(3,3),activation='relu')) classifier.add(MaxPooling2D(pool_size=(2,2))) classifier.add(Conv2D(384,(3,3),activation='relu')) classifier.add(Conv2D(384,(3,3),activation='relu')) classifier.add(Conv2D(256,(3,3),activation='relu')) classifier.add(MaxPooling2D(pool_size=(2,2))) classifier.add(Flatten()) classifier.add(Dense(units = 2048, activation = 'relu')) classifier.add(Dropout(0.5)) classifier.add(Dense(units = 2048, activation = 'relu')) classifier.add(Dropout(0.5)) classifier.add(Dense(units = 3, activation = 'softmax')) classifier.compile(optimizer = 'rmsprop', loss = 'categorical_crossentropy', metrics = ['accuracy']) return classifier
儀
def straight(): ReleaseKey(A) ReleaseKey(D) PressKey(W) def left(): ReleaseKey(D) PressKey(W) PressKey(A) def right(): ReleaseKey(A) PressKey(W) PressKey(D) def main(): model=load_model('model.model') for i in list(range(5))[::-1]: print(i+1) time.sleep(1) paused = False while(True): if not paused: screen = grab_screen(region=(0,64,640,480)) screen = cv2.resize(screen, (160,120)) screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB) screen = np.expand_dims(screen, axis = 0) prediction = model.predict(screen)[0] print(prediction) maxval=max(prediction) if prediction[1] == maxval: # straight() print('straigh',maxval) elif prediction[2] == maxval: # right() print('right',maxval) elif prediction[0] == maxval: # left() print('left',maxval) # # keys = key_check() # # if 'P' in keys: # if paused: # paused = False # time.sleep(1) # else: # paused = True # ReleaseKey(A) # ReleaseKey(W) # ReleaseKey(D) # time.sleep(1) main()
你爲什麼決定培訓這5個時代?這5個時期後的培訓和驗證/測試準確度是多少?數據集是否平衡? –
損失:10.6982 - acc:0.3363。我的數據集是平衡的。訓練時是否需要提供訓練集以外的驗證集? –
您應該有一個驗證集,以檢測過度擬合。這個損失很高,準確性很低,你要麼需要訓練模型更長的時間,要麼可以做出更深的模型。甚至在查看預測之前,你應該調整時代和學習速度。 –