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

Adds a maintenance guide page with information on maintaining vision #73

Merged
merged 48 commits into from
Aug 6, 2021
Merged
Changes from 14 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
17f20b2
Add vision guide and rearrange page numbers
ysims Jun 11, 2020
233c68f
Merge remote-tracking branch 'origin/master' into sims/guide-vision
ysims Jun 22, 2020
a317242
Merge branch 'master' into sims/guide-vision
ysims Jul 17, 2020
fc178bc
Merge remote-tracking branch 'origin/master' into sims/guide-vision
ysims Jul 17, 2020
442217f
Changes wording (minor)
ysims Jul 17, 2020
f8804ca
Merge branch 'master' into sims/guide-vision
ysims Jul 25, 2020
7427f28
Fixes merge
ysims Jul 25, 2020
a5a9dc8
Merge branch 'master' into sims/guide-vision
ysims Oct 8, 2020
2d99661
Renames to a general maintenance page
ysims Oct 8, 2020
1e607ed
Merge branch 'master' into sims/guide-vision
ysims Dec 6, 2020
5ddc67e
Merge remote-tracking branch 'origin/master' into sims/guide-vision
ysims Jan 7, 2021
2e4cbd9
Update src/book/03-guides/01-main-codebase/02-maintaining-subsystems.mdx
ysims Mar 8, 2021
414d31e
Update src/book/03-guides/01-main-codebase/02-maintaining-subsystems.mdx
ysims Mar 8, 2021
368d027
Merge remote-tracking branch 'origin/sims/guide-vision' into sims/gui…
ysims Mar 16, 2021
ed93bbf
Merge branch 'master' into sims/guide-vision
ysims Mar 30, 2021
fb6627c
Simplify NUgan and NUpbr sections
ysims Mar 31, 2021
908ce20
Merge remote-tracking branch 'origin/master' into sims/guide-vision
ysims Jun 29, 2021
abaeae3
Redo headings
ysims Jun 29, 2021
0b9bdf5
Remove NUgan - not useful anyway
ysims Jun 29, 2021
7f9691c
Apply suggestions from code review
ysims Jun 29, 2021
08adac1
Merge remote-tracking branch 'origin/sims/guide-vision' into sims/gui…
ysims Jun 29, 2021
47d2ab4
Update src/book/03-guides/01-main-codebase/02-maintaining-subsystems.mdx
ysims Jun 29, 2021
3301fc3
Just link to Visual Mesh page
ysims Jun 29, 2021
43cb092
How to export weights
ysims Jun 29, 2021
181372a
bash
ysims Jun 29, 2021
be9788c
NUgan will make its return!!
ysims Jul 3, 2021
1a83416
Updates a lot of things
ysims Jul 3, 2021
b227f06
Merge branch 'master' into sims/guide-vision
ysims Jul 3, 2021
048a509
Very small grammar mistake!!!!!
ysims Jul 3, 2021
8b8c95b
Merge branch 'master' into sims/guide-vision
ysims Jul 4, 2021
95ffb9b
Merge branch 'master' into sims/guide-vision
KipHamiltons Jul 8, 2021
6c36817
Apply suggestions from code review
ysims Jul 10, 2021
2225cd4
Better instruction for config file
ysims Jul 10, 2021
a304793
Better instructions for testing
ysims Jul 10, 2021
2b88725
Clarify recording and playing back for this purpose
ysims Jul 10, 2021
77eb137
Remove info on nano
ysims Jul 10, 2021
b2cd3a4
Fix up numbering
ysims Jul 10, 2021
071d1d2
Merge branch 'master' into sims/guide-vision
ysims Jul 11, 2021
dd8d4e1
Merge branch 'master' into sims/guide-vision
ysims Jul 13, 2021
edefb49
Merge branch 'master' into sims/guide-vision
ysims Jul 25, 2021
249fdb1
Better linking and wording for dataset stuff
ysims Jul 25, 2021
46ea8cd
Reword detector stuff
ysims Jul 25, 2021
e6fa254
link seg masks when first mentioned
ysims Jul 25, 2021
e711ad8
Merge branch 'master' into sims/guide-vision
ysims Aug 1, 2021
8f70a84
Merge remote-tracking branch 'origin/master' into sims/guide-vision
ysims Aug 5, 2021
fc90c73
Mention the mesh too with kinematics and odometry
ysims Aug 5, 2021
3be8d4d
Formatting
ysims Aug 5, 2021
3920a38
Word it a bit better
ysims Aug 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions src/book/03-guides/01-main-codebase/02-maintaining-subsystems.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
---
section: Guides
chapter: Main Codebase
title: Maintaining Subsystems
description: How to maintain subsystems within the main codebase.
slug: /guides/main/maintaining-subsystems
---

This page details how to maintain various subsystems within the main codebase.

# Vision

Before vision can work on the robot, odometry and kinematics must work on the robot. If these are inaccurate, then the green horizon will be inaccurate.

## Dataset Generation

Synthetic and semi-synthetic training data for vision can be generated using NUpbr and NUgan. Pre-generated datasets for training the Visual Mesh can be found on the Network-Attached Storage (NAS) in the lab.
ysims marked this conversation as resolved.
Show resolved Hide resolved

### NUpbr

NUpbr is a Physically Based Rendering tool created in Blender. It creates semi-synthetic images with corresponding segmentation images for training.
ysims marked this conversation as resolved.
Show resolved Hide resolved

NUpbr requires Blender **2.79**. Download the appropriate file from the [Blender 2.79 Stable Release](https://download.blender.org/release/Blender2.79/).
KipHamiltons marked this conversation as resolved.
Show resolved Hide resolved

Clone the [NUpbr repository](https://github.com/NUbots/NUpbr) using

```sh
git clone https://github.com/NUbots/NUpbr.git
```

Navigate to the NUpbr directory and run
ysims marked this conversation as resolved.
Show resolved Hide resolved

```sh
blender --python pbr.py
ysims marked this conversation as resolved.
Show resolved Hide resolved
```

Find out more about NUpbr and how to edit the parameters on the [NUpbr NUbook page](/system/tools/nupbr).

### NUgan

The NUbots CycleGAN performs style transfer from the semi-synthetic style to a real image style. It creates more realistic images from the semi-synthetic images from NUpbr. It can be used for style transfer to a specific field for fine-tuning vision.

Clone the [NUgan repository](https://github.com/NUbots/NUgan) using

```sh
git clone https://github.com/NUbots/NUgan.git
ysims marked this conversation as resolved.
Show resolved Hide resolved
```

The [NUgan repository](https://github.com/NUbots/NUgan) details how to train, test and generate images.

NUpbr images can be found on the NAS for the A datasets. The B dataset can be obtained by taking pictures, or collecting images from [Bit-Bots ImageTagger](https://imagetagger.bit-bots.de/).

### Setting Up The Data

The [Visual Mesh repository](https://github.com/Fastcode/VisualMesh) contains information on how to set up the datasets. It contains [a script](https://github.com/Fastcode/VisualMesh/blob/master/training/build_dataset.py) that takes data and converts it into the tfrecord format that the Visual Mesh expects. The script requires a folder of raw images, segmentation masks, and metadata. NUpbr will provide all these as output, and such data can be found on the NAS. If using output from NUgan, use the corresponding NUpbr segmentation masks and metadata, and add in the generated NUgan images in the image folder.
ysims marked this conversation as resolved.
Show resolved Hide resolved
ysims marked this conversation as resolved.
Show resolved Hide resolved

## The Visual Mesh

### Training

Ensure you have followed the above steps to get a dataset to train on.

As specified in the [Visual Mesh repository README](https://github.com/Fastcode/VisualMesh), install the dependencies from `requirements.txt`.
ysims marked this conversation as resolved.
Show resolved Hide resolved

```sh
pip3 install -r requirements
ysims marked this conversation as resolved.
Show resolved Hide resolved
```
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this right @Bidski?


Using [`cmake`](https://cmake.org/) and a C++ compiler with C++11 or later, build the custom TensorFlow op.

```sh
mkdir build
cd build
cmake ..
make
```
ysims marked this conversation as resolved.
Show resolved Hide resolved

A yaml file must be created with options for training. An example of this is in [the example_net.yaml file](https://github.com/Fastcode/VisualMesh/blob/master/example_net.yaml).

Execute the training by running

```sh
./mesh.py train [config.yaml] [output_dir]
```

Where `[config.yaml]` is the options yaml file as specified above, and the output directory is the name of the directory you want the progress and results to be saved to. Progress can be monitored with TensorBoard.
ysims marked this conversation as resolved.
Show resolved Hide resolved

### Testing

Testing the network is executed similarly to training. Run

```sh
./mesh.py test [config.yaml] [output_dir]
```

Where `[config.yaml]` and `[output_dir]` are the same as for training. The output will be the average precision for each class, as well as the precision/recall curves and the final mean average precision.
ysims marked this conversation as resolved.
Show resolved Hide resolved

### Exporting Configuration

The weights and biases will be output into a yaml file like the one found at [model.yaml on the Visual Mesh repository](https://github.com/Fastcode/VisualMesh/blob/master/example/model.yaml) or [VisualMesh.yaml on the NUbots repository](https://github.com/NUbots/NUbots/blob/master/module/vision/VisualMesh/data/config/VisualMesh.yaml).
ysims marked this conversation as resolved.
Show resolved Hide resolved

Replace the NUbots repository `VisualMesh.yaml` configuration with the configuration you just obtained from training the Visual Mesh. Ensure you create a new branch so you can make a PR and get any changes merged in. For further information about Git, view the [Git Guide](/guides/general/git).

## Camera Calibration

If the cameras are not calibrated correctly, the vision system will not work well. Information on calibration is available on [the input page](/system/subsystems/input).

An automatic camera calibration tool is available to use in the NUbots repository that can be used to calibrate the cameras. A guide on how to calibrate the cameras will be available on NUbook soon.
KipHamiltons marked this conversation as resolved.
Show resolved Hide resolved

## Testing

Now that the Visual Mesh has been updated in the NUbots repository, you should test it before merging.

Build the code, ensuring `VisualMesh.role` is on in `./b configure -i`. Go to the [Getting Started page](/guides/main/getting-started) to find out more on how to build the code and install onto a robot. Ensure the new configuration file has been installed. Check out the [Build System page](/system/foundations/build-system) to find out more about options when installing onto the robot.
ysims marked this conversation as resolved.
Show resolved Hide resolved

When your new Visual Mesh is installed onto the robot, connect to the robot and ensure NUsight is on.

```sh
nano config/NUsight.yaml
```

Turn `vision object` and `compressed images` on. Run NUsight using `yarn prod` and navigate to the NUsight page in your browser. More on NUsight can be found on [the NUsight page](/system/tools/nusight).

Run the visualmesh role

```sh
./visualmesh
JosephusPaye marked this conversation as resolved.
Show resolved Hide resolved
```

Wait for the cameras to load and then watch the Vision tab in NUsight. To determine if the output is correct, consult the [vision page](/system/subsystems/vision) for images of the expected output.

If you would like to see the visual mesh output in NUsight, you will need to log the data and run it back in NUsight using DataPlayback, since the data is too large to send over a network. Add into the `visualmesh.role` file `support::logging::DataLogging`. Build to the robot and rerun the visual mesh binary with `./visualmesh`. An NBS file will be created on the robot in `logs/visualmesh/`. Copy this across the network to the computer you built on using `scp <robot_address>:logs/visualmesh/<file_name> ./recordings` on the computer in the NUbots folder. Read [the Logging page](/system/subsystems/logging) to find out how to play an NBS file back.
ysims marked this conversation as resolved.
Show resolved Hide resolved

If the output has improved, create a PR and get the changes merged in to the GitHub repository. For further information about Git, view the [Git Guide](/guides/general/git).