I’m trying to control the steering of a car by getting an output between -1 ,1. Currently, I trained my network with this model.
import torch.nn as nn
import torch.nn.functional as F
# define the CNN architecture
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
# convolutional layer (sees 32x32x3 image tensor)
self.conv1 = nn.Conv2d(3, 16, 3, padding=1)
# convolutional layer (sees 16x16x16 tensor)
self.conv2 = nn.Conv2d(16, 32, 3, padding=1)
self.pool = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(32 * 4 * 4, 256)
self.fc2 = nn.Linear(256, 1)
self.dropout = nn.Dropout(0.25)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
# flatten image input
x = x.view(-1, 32 * 4 * 4)
x = self.dropout(x)
x = F.relu(self.fc1(x))
x = self.dropout(x)
x = self.fc2(x)
return x
# create a complete CNN
model = Net()
print(model)
# move tensors to GPU if CUDA is available
if train_on_gpu:
model.cuda()
Also you can see the jupyter notebook here The problem is i’m not sure what to use to get the output in real time such as np.argmax, np.max, ect…
def autopilot(self):
img = self.preprocess(self.cam.value)
count = self.cam.count
if count!= self.temp:
print('RUN!')
self.model.eval()
with torch.no_grad():
output = self.model(img)
_, angle_tensor = torch.max(output,1)
self.angle_out = angle_tensor.cpu().data.numpy()
#self.angle_out = np.argmax(output.cpu().data.numpy())#angle[0].cpu().numpy()
self.temp = count
print(self.angle_out)
else:
pass
I’m new to pytorch and i’m stuck trying to get the correct output like I did in jupyter notebook