Jetbot Training
 

Jetbot Training  

  RSS

Spyder
(@spyder)
Honorable Member
Joined: 6 months ago
Posts: 541
2019-10-16 10:18 pm  

Well, I've taken as many pictures as I care to for now, and I zipped up the picture directory the way the instructions said to, then I downloaded the file from the Jetbot (which I had to fight with cuz it told me "download forbidden")

Then it said to run it thru my host computer using the Jupyter Notebook, which didn't work at all, because the Notebook wanted to run the software on the Nano, not on my desktop

I have no idea how I'm supposed to do this at all, so I'm going to try something stupid, and see if I can copy the python program into my desktop, and then I guess I'll see if that does anything worthwhile, cuz right now it's got the Jetbot pretty much locked up. It's just giving me a msg that says "busy"

I can't imagine that I'm going to have much luck. It already failed on the unzip when I used the command that it said to use instead of unzipping the file like I normally do

If anybody cares to see what's happening, or, more likely, failing to happen, these are the programming bits that it wants me to run...

 

"Now we use the ImageFolder dataset class available with the torchvision.datasets package. We attach transforms from the torchvision.transforms package to prepare the data for training."

 

Which is probably going to mean nothing to my computer until I install torchvision, whatever that is

dataset = datasets.ImageFolder(
'dataset',
transforms.Compose([
transforms.ColorJitter(0.1, 0.1, 0.1, 0.1),
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
)

Next, we split the dataset into training and test sets. The test set will be used to verify the accuracy of the model we train.

train_dataset, test_dataset = torch.utils.data.random_split(dataset, [len(dataset) - 50, 50])

We'll create two DataLoader instances, which provide utilities for shuffling data, producing batches of images, and loading the samples in parallel with multiple workers.

train_loader = torch.utils.data.DataLoader(
train_dataset,
batch_size=16,
shuffle=True,
num_workers=4
)

test_loader = torch.utils.data.DataLoader(
test_dataset,
batch_size=16,
shuffle=True,
num_workers=4
)

Now, we define the neural network we'll be training. The torchvision package provides a collection of pre-trained models that we can use.

In a process called transfer learning, we can repurpose a pre-trained model (trained on millions of images) for a new task that has possibly much less data available.

Important features that were learned in the original training of the pre-trained model are re-usable for the new task. We'll use the alexnet model.

model = models.alexnet(pretrained=True)

The alexnet model was originally trained for a dataset that had 1000 class labels, but our dataset only has two class labels! We'll replace the final layer with a new, untrained layer that has only two outputs.

 

model.classifier[6] = torch.nn.Linear(model.classifier[6].in_features, 2)

Finally, we transfer our model for execution on the GPU

device = torch.device('cuda')
model = model.to(device)

Using the code below we will train the neural network for 30 epochs, saving the best performing model after each epoch.

(Oh goody. 30 epochs. What's that, like 30,000 years ?

NUM_EPOCHS = 30
BEST_MODEL_PATH = 'best_model.pth'
best_accuracy = 0.0

optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.9)

for epoch in range(NUM_EPOCHS):

for images, labels in iter(train_loader):
images = images.to(device)
labels = labels.to(device)
optimizer.zero_grad()
outputs = model(images)
loss = F.cross_entropy(outputs, labels)
loss.backward()
optimizer.step()

test_error_count = 0.0
for images, labels in iter(test_loader):
images = images.to(device)
labels = labels.to(device)
outputs = model(images)
test_error_count += float(torch.sum(torch.abs(labels - outputs.argmax(1))))

test_accuracy = 1.0 - float(test_error_count) / float(len(test_dataset))
print('%d: %f' % (epoch, test_accuracy))
if test_accuracy > best_accuracy:
torch.save(model.state_dict(), BEST_MODEL_PATH)
best_accuracy = test_accuracy

Does any of this make any sense to anybody ?

I recognize the word "cuda". That's a video thing that I remember installing in the Jetson, not on my desktop, which means I know this isn't going to work but I'm going to try it anyway

So... python

in a command prompt

In windows 7

This won't work. At all

 


Quote
Spyder
(@spyder)
Honorable Member
Joined: 6 months ago
Posts: 541
2019-10-16 11:40 pm  

There's an upside to not knowing what yer doing, which is that if you don't know that something yer about to try is stupid and people who do know what they're doing would say that what yer about to do won't work, you have no qualms about just going ahead and doing it

There's also a downside or course, being that what yer doing is stupid and won't work, which is why the people who do know what they're doing don't waste their time doing it

So the first thing I tried was creating 8 little python programs on my windows computer, copying over the database, and running the programs one at a time

I got as far as the first one before my computer told me in no uncertain terms that it had absolutely no idea what it was that I was trying to get it to do, and that it had no intentions of going about doing it because it had no idea exactly what it was that I was asking it to go about doing

So I copied those 8 little programs back onto the Jetson and stuck them in with the dataset I had created in one of the previous steps that I had taken which surprisingly didn't fail, and executed the first python script, or program, or whatever it is that you call the set of instructions that you created that end with the ".py" extension, and I executed the first one and was totally surprised when it worked

Well, maybe not worked exactly, but, having executed without any errors, "worked" is the term I'm going to use for now

So, I went ahead and executed the 2nd one, which didn't work.

I know this because it gave me an error 

It complained about a file called "dataset" which I had labeled in the 1st program, so, thinking that the first program might be setting something up so that the 2nd program would have something to do, I added the lines from the 2nd program to the end of the 1st program

And executed it

And it "worked".

Again, remembering that "working" doesn't exactly mean working so much as it means not visibly failing with an error message

That's 2 out of 8. That's a 25% success rate, which is an increase over the 12.5% I was at 20 minutes ago

I'm gonna call that a win

Trying to add number 3 had the same success... That's 37.5% (great job kid. Don't get cocky)

#4 gave me 50% (am I on a roll, or am I just lucky ? I'm gonna say lucky, cuz I'm honestly just guessing here. That failure has gotta be just around the corner)

Ok. This is different. Something is happening. It's downloading pytorch alexnet, and since I remember the word "alexnet" from one of the things I copy/pasted without actually paying attention to, this might be a good thing

And another no error. That's an 87% success rate so far

If I can do this one more time without an error, I will have... done something that I completely don't understand. So let's try it, eh?

Ok, I got my error finally. But, I don't think it sounds ugly...

 

jetbot@jetbot:~/jetbot/notebooks/collision_avoidance$ python3 train1.py
Traceback (most recent call last):
File "train1.py", line 44, in <module>
images = images.to(device)
NameError: name 'device' is not defined

So... maybe all I need to do is define a "device" in which to save the output ?

Can I phone a friend ?

 


ReplyQuote
Spyder
(@spyder)
Honorable Member
Joined: 6 months ago
Posts: 541
2019-10-17 12:59 am  

Google says that I need to define a device to save the output to, which is what I figured, but the problem is that in the code, there are 2 places where it says "device" so I can't just assign a single device (I think)

Posted by: @spyder

test_error_count = 0.0
for images, labels in iter(test_loader):
images = images.to(device)
labels = labels.to(device)
outputs = model(images)
test_error_count += float(torch.sum(torch.abs(labels - outputs.argmax(1))))

Well, unless there's really 2 files, with one called images.tox and labels.tox or something like that

Any ideas ?

Anybody ?


ReplyQuote
Robo Pi
(@robo-pi)
Noble Member
Joined: 6 months ago
Posts: 1041
2019-10-17 3:55 pm  
Posted by: @spyder

Well, unless there's really 2 files, with one called images.tox and labels.tox or something like that

Any ideas ?

Anybody ?

I've read through your entire description.  I'm  not going to pretend to know what it all means.  But I do have an observation, and an idea.   Not sure what the idea is worth though.

First off, the observation (which I'm not totally sure about) is has to do with the device named 'cuda'. My guess is that this is referring to the 128 core GPU.   If that's the case it's no wonder your laptop had no clue what 'cuda' means.   Your laptop doesn't have a 128 core GPU device.  I could be mistaken about this, but I've seen the 128 core GPU referred as CUDA before.

The other idea has to do with your lines:

Posted by: @spyder

model.classifier[6] = torch.nn.Linear(model.classifier[6].in_features, 2)

device = torch.device('cuda')
model = model.to(device)

I don't pretend to know how this works, but it appears that in the first line you are defining a model based on a specific classifier.  Then the line device = torch.device('cuda') looks like you are equating the device to be the 128 core GPU processor.  And the line model = model.to(device) might be excuting your model code on the GPU.

This is all just a guess on my part.

But then later where you have the following code it appears that you are trying to save images and label to the same device (i.e. the 128 core GPU).   That's probably not going to work.   So  maybe you need to redefine the device here to point to a storage device?

Posted by: @spyder

test_error_count = 0.0
for images, labels in iter(test_loader):
images = images.to(device)
labels = labels.to(device)
outputs = model(images)
test_error_count += float(torch.sum(torch.abs(labels - outputs.argmax(1))))

Again, just guessing on my part so I really have no clue.

The other thing I would ask is, Can you  install Jupyter Notebook on the Jetson Nano?   If you  have Jupyter on the Nano you should be able to execute commands that access the 128 core GPU.   You could also try executing the above code from Jupyter using different devices and see if you can get that part of the code to work.

Just my thoughts for whatever they might be work.  Like I say, I have no clue, I'm just taking a stab at this in the dark.   I figure any suggestions are better than no suggestions at all. 😊 

So I figured it wouldn't hurt to reply.

DroneBot Workshop Robotics Engineer
James


ReplyQuote
Spyder
(@spyder)
Honorable Member
Joined: 6 months ago
Posts: 541
2019-10-17 6:48 pm  
Posted by: @robo-pi

you  install Jupyter Notebook on the Jetson Nano? 

Yes. In fact I already figured out about the cuda so the data I posted was running on the nano

Posted by: @robo-pi

So  maybe you need to redefine the device here to point to a storage device?

I think figuring that part out is the solution

Remember, I didnt write that code. It came from nvidia. Thats the part i cant figure out, its a couple hundred pictures that its sorting thru, and the output goes to, what ? 2 files ?

Is that even what it says its doing ?

Does it just want a home for the 2 files, and its up to me to assign it ?


ReplyQuote
Robo Pi
(@robo-pi)
Noble Member
Joined: 6 months ago
Posts: 1041
2019-10-17 7:27 pm  
Posted by: @spyder

I think figuring that part out is the solution

Remember, I didnt write that code. It came from nvidia. Thats the part i cant figure out, its a couple hundred pictures that its sorting thru, and the output goes to, what ? 2 files ?

Is that even what it says its doing ?

Does it just want a home for the 2 files, and its up to me to assign it ?

Sounds like you're on the right track.   That would be my guess as well.  This is why I was suggesting using Jupyter Notebook on the Nano.   If you have Jupyter Notebook on the Nano you could try just executing the commands:

for images, labels in iter(test_loader):
images = images.to(device)
labels = labels.to(device)

While changing "device" to something like "SD card" (or however you access your SD card).

And then see if that creates two files on your SD card called images and labels?

Posted by: @spyder

Remember, I didnt write that code. It came from nvidia.

That explains everything. 🤣 

Is there a forum where you can ask questions?

It's going to be a very long time before I catch up to where you're at.   I'm going to patiently go through Paul McWhorter's entire course on how to write these programs.   Hopefully by the end of the course I'll have some clue about these things.

In the meantime I would be just as lost as you are if I got code from nvidia that didn't just work right out of the box.   Maybe they were using "device" as a generic name and expect you to fill in the proper devices for your system?

That's all I can figure.

DroneBot Workshop Robotics Engineer
James


ReplyQuote
Spyder
(@spyder)
Honorable Member
Joined: 6 months ago
Posts: 541
2019-10-18 2:52 am  
Posted by: @robo-pi

If you have Jupyter Notebook on the Nano you could try just executing the commands:

Um, yea. In the first post in this thread, maybe I didn't make it clear cuz it was too ridiculous to actually believe, but, I broke up the post into 8 sections because that's how nvidia put it into the Jupyter Notebook, in 8 separate sections that, separately, didn't do a blasted thing until I had the idea that it might be a SINGLE program and started executing them by adding them together one piece at a time

It was stupid of me to think of such a thing, or so I thought at the time, until it started working, which was, of course, right before it failed

I did, originally try running it on my desktop, but, I recognized cuda as something that had to do with nvidia, and, well, running python on windows was challenging enough, so, I did run it on the Jetson, and I had already tried running it step by step in the Jupyter, but, it failed instantly, and, like I said, it didn't start doing something positive until I put all the pieces together into one program

I did try to define a variable for the output to go to, but, that didn't work, which could have been because I have no idea what I'm doing, or because you might be right, and maybe I should just tell it to go to the SD card

Posted by: @robo-pi

I figure any suggestions are better than no suggestions at all. 😊 

Yes, and I appreciate it. A second set of eyes usually gives me ideas that I overlook

Posted by: @robo-pi

It's going to be a very long time before I catch up to where you're at

Until I succeed at something here, I'm not very far ahead of you, now, am I ?

I mean, I haven't actually done anything on my own here. I downloaded a prebuilt software package. I bought only hardware that was specified in the BOM. All of which you could do tomorrow with their motorboard, PiOLED, and a couple of motors. The only thing I did on my own was print a different body style and use different wheels and motors. It would probably have worked out better with their plans due to the fact that I obviously made this project take longer cuz of all the failures with my body and tank track ridiculousness

All because I wanted to make it look cool instead of having it work the way they designed it

In fact, you're probably ahead of me cuz you're learning what you're doing, while I'm just blundering on without a clue

I will say this tho. Their battery option DOESN'T work. It works for testing to see if the nano turns on and runs, but, once you start putting a load on it, the thing shuts down. A fact which frustrated me for a full day until I decided to yank out some of the 18650 batteries from my steampunk laptop and install them in the car (I installed 8 of them in the laptop. Talk about overkill. I probably could have started my motorcycle from it)

4 of those batteries going thru a buck converter ran that thing for a full 4 hours at load !

I was suitably impressed at that

I wonder what would happen if I decided to skip the whole training thing, and just try to have it follow me

I mean, it wouldn't run into a wall or anything as long as I didn't run into the wall first, right ?

Heck, it's going into my toolbox, so there isn't much chance of it driving off a table since there isn't a table big enough to put it on in the first place

Oh, and I did try their forum. You should check out their forum. It's full of people with questions and ZERO responses

Just one page on their forum has 15 questions, and 11 have ZERO responses. And theoretically this page is monitored by people at Nvidia. There's one question there that's been there for 2 years, without a single response. And that's just page ONE

I've got a question posted over there, but I'm not expecting any help from them anytime soon, if ever


ReplyQuote
Robo Pi
(@robo-pi)
Noble Member
Joined: 6 months ago
Posts: 1041
2019-10-18 3:19 am  
Posted by: @spyder

Yes, and I appreciate it. A second set of eyes usually gives me ideas that I overlook

That's what I figured.  Even if I offer up something really stupid it might cause you to think of something brilliant. 😊 

Posted by: @spyder

n fact, you're probably ahead of me cuz you're learning what you're doing, while I'm just blundering on without a clue

I just now came from Paul McWhorter's YouTube channel.   His lesson plans look like they are going to be painfully slow!    One once-a-week on Saturdays.   And it doesn't look like he's going to be getting into anything truly interesting for at least the next 3 weeks!

Of course, right now I don't have time to do this anyway, so no loss yet.  But later when I actually start getting into it I imagine it's going to be painful having to wait so long for each new lesson.

Fortunately I'm working on a lot of other aspects of my robots too, so there's no rush for the A.I. stuff anyway.  I just received a package today with 150 LM324  Quad Op-Amps that I'm hoping to use for designing hardware ANNs.  And no, I don't expect to use all 150 of them.  They were CHEAP, especially when ordered in large quantities, so why not?  Better having too many than not enough.

These are also DIP-8 packages just for breadboard prototyping.   So where I'm going with this I have no clue.  I just want to play around with them and see what I can do with the least amount of chips possible.  I expect that I'll need to do a lot of experimenting with simple perceptrons long before I try any complex ANNs with multiple layers.   So this isn't anything I expect to happen over night.   I just like to play with this stuff.  It's cheap enough so if it all ends in a bust it will have been fairly cheap entertainment anyway. 😎 

Worst case scenario is that I'll end up using the Op-Amps for some sort of analog robotics control in some fashion anyway.   I'm really doing most of this to keep my brain active.  They say that's the best way to prevent Alzheimer's from setting in.  Besides, it's fun!

DroneBot Workshop Robotics Engineer
James


ReplyQuote
Spyder
(@spyder)
Honorable Member
Joined: 6 months ago
Posts: 541
2019-10-18 4:01 am  

@robo-pi

I can't find the link. I just read an article a few days ago about  a guy who built a robot from a 1970's instruction manual using original specs. Meaning that he had to manually program the thing every time he turned it on, which took like an hour or so

But this link should interest you also. It's got some interesting op-amp projects in it

Analog robotic concepts

Posted by: @robo-pi

it might cause you to think of something brilliant. 😊 

I can't imagine anybody referring to anything I do as brilliant, unless stolen intellectual property comes into vogue, and I believe that China may have the market cornered in that area anyway


ReplyQuote
Robo Pi
(@robo-pi)
Noble Member
Joined: 6 months ago
Posts: 1041
2019-10-18 6:10 am  
Posted by: @spyder

But this link should interest you also. It's got some interesting op-amp projects in it

Oh yeah!   Thanks for the link Spyder!  That's right up my alley.  I love the analog stuff.   People get so used to using microcontrollers they either forget (or never knew) that they can do a lot of this stuff just as easily, and sometimes even better, using simple analogy circuits.

By the way, I got 50 NE555 Timer chips in with that same Op-Amp order.  So I'm all set to go with the 555 timers.   I always loved that chip.  It's so versatile in what it can do.   I also got some LM741 and LM386 Op-Amps.  These old linear chips are always great fun to work with.

I see this guy had some videos on analogy perceptrons too.  Unfortunately he said that they are in another video but I didn't see the perceptron video on that YouTube Channel.  I'd like to see that video.   Maybe it's there and I just didn't see it.  I'm tired and I'm going to bed.

Thanks for the link.   Love it! 👍

DroneBot Workshop Robotics Engineer
James


ReplyQuote

Please Login or Register