Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 59 additions & 0 deletions INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<h1>Setup</h1>
To begin setup.<br><br>

1. I forked the original Caxton repo:<br>
<a href="https://github.com/cam-cambridge/caxton">https://github.com/cam-cambridge/caxton</a><br><br>

2. I cloned my "Caxton_Fork" to `gebru` using:<br>
<code>git clone git@github.com:philip-hub/caxton_fork.git</code><br><br>

3. I created a virtual environment:<br>
<code>python3 -m venv env</code><br>
I then activated my environment:<br>
<code>source env/bin/activate</code><br><br>

4. I ran the command to install requirements:<br>
<code>pip install requirements.txt</code><br>
This at first did not work and I had to edit the `requirements.txt`. I removed <code>dataclasses==0.8</code> as this is no longer needed for Python 3.7 and higher. I opened a pull request back to the original Caxton repo since this was the only change needed for training to run.<br><br>

<h1>Data</h1><br>

5. I downloaded the data from <a href="https://www.repository.cam.ac.uk/items/6d77cd6d-8569-4bf4-9d5f-311ad2a49ac8">this dataset page</a>. Specifically, I downloaded <a href="https://www.repository.cam.ac.uk/bitstreams/54554b08-6ac5-495f-8d51-9c614d6839f7/download">caxton_dataset_filtered.csv</a>. I also consulted with Dr. Wilson and downloaded <a href="https://www.repository.cam.ac.uk/bitstreams/ec724f7c-14e3-464d-b031-372cd2765a03/download">print0.zip</a>, which I unzipped. I decided to train the model using only these images.<br><br>

6. To train only with print0, I ran a script that drops entries not associated with the print0 dataset. This script is in <a href="https://github.com/philip-hub/caxton_fork/blob/main/extras/main.py">extras/main.py</a>. Make sure that the print0 images are placed in the appropriate path. See the README in the extras folder for more details.<br><br>

7. I moved the `print0` folder to <code>data/caxton</code> and placed the outputted <code>caxton_data_filtered.csv</code> into the <code>data/</code> directory.<br><br>

8. Final training step: start the training (ensure your virtual environment is activated):<br>
<code>python src/train.py</code><br>
This successfully trained my model!<br><br>

<h1>Testing</h1>

9. To run the test file, locate your checkpoint file after training. Mine was:<br>
<code>src/checkpoints/21052025/1234/MHResAttNet-dataset_full-21052025-epoch=09-val_loss=37.10-val_acc=0.46.ckpt</code><br><br>

Use Vim or a Visual Studio SSH client to open and edit `test.py`. On line 19, set the path:<br>
<code>checkpoint_path = "/home/poundspb/Computer Vision/caxton_fork/src/checkpoints/21052025/1234/MHResAttNet-dataset_full-21052025-epoch=09-val_loss=37.10-val_acc=0.46.ckpt"</code><br><br>

10. Run test.py:<br>
<code>python src/test.py</code><br>
This will show you the test accurcy and loss.

<h1>Running with real world samples</h1>

9. To run the sample file, locate your test image path. Upload your images to the path. Mine was:<br>
<code>/home/poundspb/Computer Vision/caxton_fork/data/full/</code><br><br>

Use Vim or a Visual Studio SSH client to open and edit `test.py`. On line 20, set the path you located in step 9:<br>
<code>checkpoint_path = "/home/poundspb/Computer Vision/caxton_fork/src/checkpoints/21052025/1234/MHResAttNet-dataset_full-21052025-epoch=09-val_loss=37.10-val_acc=0.46.ckpt"</code> And then on line 29 change to your image path

<code>sample_data = "/home/poundspb/Computer Vision/caxton_fork/data/full/"</code>

Run samples.py
<code>python src/samples.py</code><br>

*Note I had to make a few changes to samples.py for it to work.
* Other note I used chatgpt on this project
<br><br>

46 changes: 46 additions & 0 deletions SAMPLE_OUTPUT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Testing output
<code>

(env) poundspb@gebru:~/Computer Vision/caxton_fork/src$ python test.py
Global seed set to 1234
GPU available: True, used: True
TPU available: None, using: 0 TPU cores
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0,1,2,3,4,5,6,7]
Using native 16bit precision.
Testing: 0it [00:00, ?it/s]/home/poundspb/Computer Vision/caxton_fork/env/lib/python3.9/site-packages/pytorch_lightning/core/step_result.py:145: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
value = torch.tensor(value, device=device, dtype=torch.float)
Testing: 100%|██████████████████████████████████████████████████████████| 9/9 [00:01<00:00, 5.32it/s]
--------------------------------------------------------------------------------
DATALOADER:0 TEST RESULTS
{'test_acc': tensor(0.5448, device='cuda:0'),
'test_acc_epoch': tensor(0.5448, device='cuda:0'),
'test_loss': tensor(3.7239, device='cuda:0'),
'test_loss0': tensor(0.9406, device='cuda:0'),
'test_loss1': tensor(0.9644, device='cuda:0'),
'test_loss2': tensor(0.8445, device='cuda:0'),
'test_loss3': tensor(0.9130, device='cuda:0'),
'test_loss_epoch': tensor(3.6625, device='cuda:0')}
</code>

Sample Output

<code>

(env) poundspb@gebru:~/Computer Vision/caxton_fork/src$ python samples.py
********* CAXTON sample predictions *********
Flow rate | Lateral speed | Z offset | Hotend
*********************************************
Input: IMG_3438.jpg -> Prediction: [0 0 2 2]
Input: IMG_3436.jpg -> Prediction: [0 0 2 2]
Input: sample0021.jpg -> Prediction: [0 0 2 2]
Input: sample1221.jpg -> Prediction: [0 0 2 2]
Input: sample1111.jpg -> Prediction: [0 0 2 2]
Input: IMG_3437.jpg -> Prediction: [0 0 2 2]
Input: sample1011.jpg -> Prediction: [0 0 2 2]
Input: sample2120.jpg -> Prediction: [0 0 2 2]
Input: sample0022.jpg -> Prediction: [0 0 2 2]
Input: sample2122.jpg -> Prediction: [0 0 2 2]
Input: sample2011.jpg -> Prediction: [0 0 2 2]
Completed 11 predictions in 1.84s

</code>
1 change: 1 addition & 0 deletions data/caxton_dataset/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
After running the script move he unzipped files here
Loading