Skip to content

Adding torch examples#15

Merged
glopesdev merged 30 commits intomainfrom
dev/torch-examples
May 2, 2025
Merged

Adding torch examples#15
glopesdev merged 30 commits intomainfrom
dev/torch-examples

Conversation

@ncguilbeault
Copy link
Copy Markdown
Collaborator

@ncguilbeault ncguilbeault commented Jan 23, 2025

This PR introduces new examples for the Bonsai.ML.Torch package in bonsai-rx/machinelearning#48. A list of examples and brief summaries are provided below.

Examples

Linear Regression

In this example, the Bonsai.ML.Torch package is used to perform simple linear regression using the ordinary least squares method on simulated data.

Neural Nets - Pretrained Model

This example shows how to run inference using a pretrained convolutional neural network to solve a typical image classification problem. The network is trained to categorize clothing items in the fashion-mnist dataset and perform online inference of new images that were not included in the training dataset. In this particular example, the pretrained weights of the model are loaded from disk.

Neural Nets - Torch Hub

This example shows how a PyTorch model can be downloaded from the PyTorch hub and used to run online inference in Bonsai. For this particular example, the MiDaS model is used to infer the relative inverse depth of images streamed from a camera.

Neural Nets - Training Online

This example shows how a convolutional neural network can be trained online to solve an image classification problem. It demonstrates a typical training procedure that involves performing SGD on the weights of the network as new images and labels are passed to the network. After a certain amount of training, the model can be switch to online inference only mode.

Running On Mono

This example demonstrates how to run the package on Mono. This currently requires a workaround to the DLL import which explicitly throws an error on non-windows OS's running .NET Framework (which is the case for Mono). See this issue: dotnet/TorchSharp#689.

Copy link
Copy Markdown
Member

@glopesdev glopesdev left a comment

Choose a reason for hiding this comment

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

Everything looks good, just a few suggestions to smooth out the process. Created a branch dev/torch-examples-torchhub with a suggestion to improve python bootstrapping using uv.

Comment thread examples/Torch/NeuralNetsPretrainedModel/Extensions/FashionMnistLoader.cs Outdated
Comment thread examples/Torch/NeuralNetsPretrainedModel/NeuralNetsPretrainedModel.bonsai Outdated
Comment thread examples/Torch/NeuralNetsPretrainedModel/README.md Outdated
Comment thread examples/Torch/NeuralNetsTorchHub/README.md Outdated
Comment thread examples/Torch/NeuralNetsTorchHub/README.md
Comment thread examples/Torch/NeuralNetsTrainedOnline/Extensions/FashionMnistLoader.cs Outdated
Comment thread examples/Torch/NeuralNetsTrainedOnline/NeuralNetsTrainedOnline.bonsai Outdated
Comment thread examples/Torch/NeuralNetsTrainedOnline/NeuralNetsTrainedOnline.sln Outdated
Comment thread examples/Torch/NeuralNetsTrainedOnline/README.md Outdated
Copy link
Copy Markdown
Collaborator Author

@ncguilbeault ncguilbeault left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback. I think I've addressed all of the comments from the previous review. Let me know what you think!

@ncguilbeault ncguilbeault requested a review from glopesdev April 30, 2025 13:40
@glopesdev glopesdev merged commit df7e95f into main May 2, 2025
1 check passed
@glopesdev glopesdev deleted the dev/torch-examples branch May 2, 2025 11:59
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.

2 participants