Skip to content

Add YOLO PreProcessor#25

Merged
saksham189 merged 9 commits into
mlpack:masterfrom
kartikdutt18:YOLOPreProcessor
Sep 11, 2020
Merged

Add YOLO PreProcessor#25
saksham189 merged 9 commits into
mlpack:masterfrom
kartikdutt18:YOLOPreProcessor

Conversation

@kartikdutt18

@kartikdutt18 kartikdutt18 commented Jul 11, 2020

Copy link
Copy Markdown
Member

Hey everyone,
This PR aims to add preprocessor function for YOLO class. This basically converts annotations into feature maps that can be used for training YOLO model i.e. have the same format as output of YOLO model.
To Do :

  • Add tests to verify output.

CC : @KimSangYeon-DGU, @saksham189, @zoq

@kartikdutt18 kartikdutt18 marked this pull request as ready for review July 13, 2020 08:52
@kartikdutt18 kartikdutt18 changed the title [WIP] Add YOLO PreProcessor Add YOLO PreProcessor Jul 13, 2020

@zoq zoq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great to me, from the first comment it sounds like the next step is to implement/extend the test case.

Comment thread dataloader/preprocessor.hpp
Comment thread dataloader/preprocessor.hpp
@saksham189

Copy link
Copy Markdown
Member

Hey @kartikdutt18 , I just wanted to know whether you were stuck anywhere with this because we were planning to finish this first.

@kartikdutt18

kartikdutt18 commented Jul 21, 2020

Copy link
Copy Markdown
Member Author

Hey @saksham189, I've probably written some expression wrong somewhere and I wasn't able to track it down before Saturday so as it was decided to start with the translator from Saturday, I implemented the weight translator here so we can now transfer weights of Darknet model or any other model from PyTorch to mlpack. However other than weights we also need to transfer running mean and variance for BatchNorm Layer and with that I'm stuck with the error here. I'll take a look at the preprocessor again today. In the meanwhile, I tried training Darknet 19 model on Cifar10, It didn't converge, so I also added Darknet 1 (same as YOLO model) on Cifar10 to see if we can train that and it takes 3 hours for a single epoch so we should also be able to train YOLO model (in less time than Darknet), if needed. Here is the log for the first epoch (20% accuracy).
21_log_epoch
Kindly let me know what you think.

@saksham189

Copy link
Copy Markdown
Member

Looks good and the training time is also considerably lower. So, maybe we should just train that first and look at the accuracy.

@kartikdutt18

Copy link
Copy Markdown
Member Author

Looks good and the training time is also considerably lower. So, maybe we should just train that first and look at the accuracy.

Great, I'm letting the model train. In the meanwhile, I will try to get running mean and variance also loaded into mlpack. Also, with transferred weights we can also train the model on imagenette (that way running mean and variance will be set in training).

@kartikdutt18

Copy link
Copy Markdown
Member Author

Hey @saksham189, I fixed the errors in the implementation as well added tests fro single image, multiple images and image with multiple bounding box.

arma::vec desiredSum(3);
desiredSum << 8.3342 << 18.4093 << 7.13195 << arma::endr;
for (size_t i = 0; i < output.n_cols; i++)
BOOST_REQUIRE_CLOSE(arma::accu(output.col(i)), desiredSum(i), 1e-3);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we should also compare the normalized boxes with pre calculated ones, what do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, I can add that as well.

Comment thread dataloader/preprocessor.hpp
Comment thread dataloader/preprocessor.hpp
@kartikdutt18

Copy link
Copy Markdown
Member Author

So, maybe we should just train that first and look at the accuracy.

Hey @saksham189, @KimSangYeon-DGU, I continued the training. Initially it was for 5 epochs (the learning rate was 0.01) and after 5 epochs it remained constant and the below graph was obtained. Then, I set learning rate to 0.001 and it's still training and has completed nearly 25 epochs out of 40. The training and validation accuracy are continuously increasing from 20% and 7% respectively to 31% and roughly 20%. The graph for that is also attached below. Also, about using larger image sizes such as imagenette, The training time doesn't change significantly with larger images however time for loading the dataset is very large. Imagenette with 320 x 320 x 3 image size and 5k images nearly took an hour.
Current training log (lr = 1e-3).
darknet_v1_fast_mean_log_epoch
darknet_v1_fast

First attempt to train (5 epochs / lr = 1e-2) (training accuracy = 26%, Graphs are shown below)
darknet_v1_slow_mean_log_epoch
darknet_v1_slow
I'll add the changes for YOLOv3 in a couple of minutes. Then I would also have to add tests for the same.

@saksham189 saksham189 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks mostly good to me! Just one minor comment.

Comment thread dataloader/preprocessor.hpp
@kartikdutt18 kartikdutt18 mentioned this pull request Aug 26, 2020
3 tasks

@KimSangYeon-DGU KimSangYeon-DGU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left minor comments about styles

Comment thread dataloader/preprocessor.hpp
Comment thread dataloader/preprocessor.hpp Outdated
Comment thread dataloader/preprocessor.hpp Outdated
Comment thread dataloader/preprocessor.hpp Outdated
Comment thread dataloader/preprocessor.hpp Outdated
@kartikdutt18

Copy link
Copy Markdown
Member Author

I think this is ready to go as well.

@KimSangYeon-DGU KimSangYeon-DGU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the late response. I left a question for me to get understood this feature.

Comment on lines +102 to +104
* @param annotations Field object created using model's dataloader containing
* annotation for images.
* @param output Output matrix where output will be stored.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @kartikdutt18, can you explain the input, output, and terms of cell and grid which are used in this implementation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hey @KimSangYeon-DGU, no worries, The input here would be a field type containing bounding boxes, the output would be an arma::mat which be would be of size batchSize * (featureMapSize) where featureSize would correspond to S * S * (numBoundingBoxes * (numClasses + 5)) for YOLOv3 and S * S * (numBoundingBoxes * 5 + numClasses). Here cell is a single cell / data point in Feature Size. And the grid is featureSize reshaped as a cube (S, S, (numBoundingBoxes * 5 + numClasses)).

@KimSangYeon-DGU KimSangYeon-DGU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me.

@mlpack-bot mlpack-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Second approval provided automatically after 24 hours. 👍

@saksham189 saksham189 merged commit 27c4814 into mlpack:master Sep 11, 2020
@saksham189

Copy link
Copy Markdown
Member

Thanks for the great contribution @kartikdutt18 !

@kartikdutt18

Copy link
Copy Markdown
Member Author

Thanks lot @KimSangYeon-DGU, @saksham189, @zoq for the reviews and all the help. Also, thanks a lot for mentoring me during GSoC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants