Im attempting to make a self driving car the input is a list of values from game. the out put is a list of
“wasd” being pressed or not eg.[0,1,0,1] i think the correct thing for me to do would be a Multi hot vector (gas and turn at the same time) but how do I get out put from this? Right now im using ive manually tried various sample data but output doesnt change and is a digit. Since I have 4 output nodes would that mean i just convert to binary eg 3 would be [0,0,1,1]and then that would be my controls?
import torch import torchvision from torchvision import transforms,datasets import numpy as np import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch.utils.data import TensorDataset, DataLoader np_load_old = np.load np.load = lambda *a, **k: np_load_old(*a, allow_pickle=True, **k) train_data = np.load('training_datav2.npy') np.load = np_load_old training_inputs=  training_outputs=  for row in train_data: training_inputs.append(row) training_outputs.append(row) trainX= training_inputs[:len(training_inputs)//2] testX= training_inputs[len(training_inputs)//2:] trainY= training_outputs[:len(training_outputs)//2] testY= training_outputs[len(training_outputs)//2:] my_x = np.array(trainX) # a list of numpy arrays my_y = np.array(trainY) # another list of numpy arrays (targets) tensor_x = torch.Tensor(my_x) # transform to torch tensor tensor_y = torch.Tensor(my_y) trainDataset = TensorDataset(tensor_x,tensor_y) my_testx = np.array(testX) # a list of numpy arrays my_testy = np.array(testY) # another list of numpy arrays (targets) tensor_testx = torch.Tensor(my_testx) # transform to torch tensor tensor_testy = torch.Tensor(my_testy) testDataset = TensorDataset(tensor_testx,tensor_testy) class Net(nn.Module): def __init__(self): super().__init__() self.fc1=nn.Linear(5,10) self.fc2=nn.Linear(10,10) self.fc3=nn.Linear(10,5) self.fc4=nn.Linear(5,4) def forward(self,x): x=F.relu(self.fc1(x)) x=F.relu(self.fc2(x)) x=F.relu(self.fc3(x)) x=(self.fc4(x)) return x net = Net() print(net) optimizer= optim.Adam(net.parameters(),lr=0.001) criterion = torch.nn.MSELoss() EPOCHS = 1 for epoch in range(EPOCHS): count=0 for data in trainDataset: x,y=data net.zero_grad() out=net(x) loss= criterion(out,y) loss.backward() optimizer.step() count+=1 print(loss) correct =0 total=0 with torch.no_grad(): for data in testDataset: x, y = data out = net(x) for idx, i in enumerate(out): if torch.argmax(i)==y[idx]: correct+=1 total+=1 guess=torch.argmax(net(torch.Tensor([11, 0, 1, 0, -0.18750000000000006]))) print(guess) print("Accuraccy:",round(correct/total,3))
Accuracy is on 65% at the moment with about 6700 samples i would like more but i feel like this should be good enough to make sure its working any advice is appreciated.