Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding FastAI(pytorch) as a first class citizen to the pipeline #982

Merged
merged 8 commits into from Feb 23, 2022
Merged

Conversation

adricl
Copy link
Contributor

@adricl adricl commented Jan 17, 2022

This PR allows you to use Fast AI(pytorch) end to end in donkey car. I have tested training and driving with the simulator.

I have added a new type of model fastai_ so far linear is the only model implemented. More can be added in the future of course.
I have tried my best to emulate most of the function that Keras does but there are some idiosyncrasies between the two frameworks.

These normal training and driving commands work.
python train.py --tubs data/ --model models/fastai_linear_model.pth --type fastai_linear
python manage.py drive --model models/fastai_linear_model.pth --type fastai_linear

I do realise that this PR comes without a heads up or warning so if its rejected that's fine.
I do really like this project and the work that has been done, its just I prefer PyTorch to TensorFlow.

Any suggestions are welcome. I am new to python of this complexity so any pointers would be great.
There will be more cleanups and fixes on this PR as I am not finished yet. I need to add some graph plotting and other tidy ups and maybe a refactor. Any guidance would be great.
I will also add some docs around this.

If this goes well I might also look at getting pytorch lightning into own part and working in the pipeline.

Please note this will not work with TensorRT or TF lite if there is demand I could look at this in the future.

Cheers

@DocGarbanzo
Copy link
Contributor

@adricl - are you still working on this PR? It will take a bit to go through this. You should definitely make sure that the tests are passing. If you are still working on it, then you can convert the PR to draft.

@adricl adricl closed this Jan 18, 2022
@adricl adricl reopened this Jan 18, 2022
@adricl adricl marked this pull request as draft January 18, 2022 22:09
@adricl
Copy link
Contributor Author

adricl commented Jan 18, 2022

@DocGarbanzo
Thanks for that, I know its a big piece of work. Sorry about that.
I am trying to get the tests to pass. I have converted it to draft,.

@adricl adricl marked this pull request as ready for review January 18, 2022 22:11
@adricl adricl marked this pull request as draft January 18, 2022 22:11
@tikurahul
Copy link
Collaborator

One more thing. When you are ready, can you please squash your changes to a single commit ? That way it becomes easier to reason about.

@adricl adricl marked this pull request as ready for review January 23, 2022 06:20
@adricl adricl marked this pull request as draft January 23, 2022 06:21
@adricl
Copy link
Contributor Author

adricl commented Jan 23, 2022

@tikurahul to squash the commit do I have to create a new PR or can I do it in this existing PR? I am not sure how to go about it if you can do it for the existing pr. Thanks

@adricl adricl marked this pull request as ready for review January 23, 2022 07:45
@adricl
Copy link
Contributor Author

adricl commented Jan 23, 2022

I think this pr is good to review now..

I can recreate this PR if required into a squash if you want.

@DocGarbanzo
Copy link
Contributor

@adricl - you don't need to do a new PR. You can squash the commits on your branch, make sure everything is working and force-push. It will update this PR here in-place.

Copy link
Contributor

@DocGarbanzo DocGarbanzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a great idea to bring in fastai. A couple of points need to be addressed. Please also add a test for the fastai model - you can compare how @EricWiener adapted the Keras tests to PyTorch. We should test the functionality of the model and the pipeline and the training. The latter should be switched off in the CI (we have the same setup also for TF and PyTorch).

donkeycar/parts/fastai.py Outdated Show resolved Hide resolved
donkeycar/parts/fastai.py Outdated Show resolved Hide resolved
donkeycar/parts/fastai.py Show resolved Hide resolved
donkeycar/parts/fastai.py Show resolved Hide resolved
donkeycar/parts/interpreter.py Show resolved Hide resolved
donkeycar/pipeline/training.py Outdated Show resolved Hide resolved
donkeycar/pipeline/training.py Show resolved Hide resolved
donkeycar/utils.py Outdated Show resolved Hide resolved
donkeycar/parts/interpreter.py Outdated Show resolved Hide resolved
donkeycar/utils.py Outdated Show resolved Hide resolved
@adricl adricl closed this Jan 26, 2022
@adricl adricl reopened this Jan 26, 2022
@adricl
Copy link
Contributor Author

adricl commented Jan 26, 2022

I have to look at the tests next. That might take me a few days.

@@ -36,6 +37,7 @@ dependencies:
- plotly
- pyyaml
- tensorflow=2.2.0
- fastai
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add the module in setup.py. Do you know if this installs on the RPi w/o problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should work as fastai is a wrapper around pytorch so there is no binaries as such. I will test this.

@DocGarbanzo
Copy link
Contributor

@adricl - this looks much better now.

@Bleyddyn
Copy link
Contributor

Thanks for this. I had just started working on the same idea but I haven't gotten nearly as far.
I have a notebook that has a working DataBlock for loading v2 Tub files, but I'm still trying to figure out how to train using it: https://github.com/Bleyddyn/malpi/tree/master/notebooks

@adricl
Copy link
Contributor Author

adricl commented Jan 30, 2022

@Bleyddyn off topic but this is how it was done in Tub V1 link (not by me). This was a very clean implementation. I have created a notebook so we can experiment with models but its not releasable as yet. I will have to rewrite it for this PR.

@DocGarbanzo
Copy link
Contributor

@adricl @Bleyddyn - if you want to put records into a data frame as in the example above, this is now much easier with the new tub, because it is an Iterable over dictionaries. You just say:

import pandas as pd
from donkeycar.parts.tub_v2 import Tub
t = Tub('/home/me/mycar/data')
df = pd.DataFrame(t)

@Bleyddyn
Copy link
Contributor

Bleyddyn commented Feb 1, 2022

@DocGarbanzo That's what I'm doing in the notebook I linked to. Updated now with a better DataBlock definition and actual working training code.

@DocGarbanzo
Copy link
Contributor

@Bleyddyn - just looked at your notebook now. Very good.

I will need to remove the code around tflite and tensor rt for fastai.
@adricl
Copy link
Contributor Author

adricl commented Feb 12, 2022

@DocGarbanzo I have updated the test train pipeline to run fastai. I have also added fastai to the pi build. Is there anything else that needs to be completed for this PR?

Copy link
Contributor

@DocGarbanzo DocGarbanzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very good now, can you please address the small comment on the test & push it, then I'll merge the code.

donkeycar/tests/test_train.py Outdated Show resolved Hide resolved
@adricl
Copy link
Contributor Author

adricl commented Feb 18, 2022

We are good to go!

@DocGarbanzo DocGarbanzo merged commit 064b327 into autorope:dev Feb 23, 2022
@c1505
Copy link

c1505 commented Mar 1, 2022

Awesome contribution here ! I would like to try this out in the simulator and/or on a car. Any docs associated with this update or plan to create/modify some ? I can help review/validate the doc changes . @adricl

@adricl
Copy link
Contributor Author

adricl commented Mar 1, 2022

Thanks,
I will have to add documentation at some stage.
Basically you need to train and load with type = "fastai_linear". This will will work end to end with the simulator as that is where I was running it.
I will get onto the docs asap.

@adricl
Copy link
Contributor Author

adricl commented Mar 5, 2022

@c1505 this is my documentation. FastAi Docs Have a look before I merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants