-
Notifications
You must be signed in to change notification settings - Fork 2k
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
WIP: Correct computing offset of anchors. #1075
Conversation
keras_retinanet/utils/anchors.py
Outdated
# compute the offset of the anchors based on the image shape and the feature map shape | ||
# see https://github.com/fizyr/keras-retinanet/issues/1073 for more information | ||
offset_x = (image_shape[1] - (features_shape[1] - 1) * stride) / 2 | ||
offset_y = (image_shape[0] - (features_shape[0] - 1) * stride) / 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to support python 2.X, better divide by 2.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I wish we weren't supporting 2.x, but unfortunately we are :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @jonilaserson for catching this 🥇
@hgaiser before merging let's wait for COCO to be trained both for keras-retinananet and keras-maskrcnn. We should also properly announce this change on the slack channel and bump the release to 0.6.0.
I've also modified the tensorflow
The original results:
There's a difference there, which makes sense. The difference for IoU=0.5 is rather small, but the difference for IoU=0.75 is large (causing the difference in mAP to be relatively large as well). Basically all detections have been shifted a few pixels to the top left corner, which isn't that critical with a lenient overlap threshold of 0.5, but for 0.75 it is more severe. Next I'll start a training process to finetune the network for this new setting, and add unit tests for this function. |
Added unit tests and started training starting from the previous best weights. The first epoch moved the mAP from 0.286 to 0.333, so that's a nice first increase. I'll see how far it gets, hopefully it becomes at least as accurate as the original model :) I'm awaiting the results of training (and that of keras-maskrcnn) before merging this. We'll have to tag it as a new version as well. |
Check #1073 for more information.
This is still on my radar btw, but it takes a while to retrain. So far the best mAP I got was 0.343, I'm trying to see if I can push it closer to 0.350 (with simply more training). |
Thanks for the update, Hans! It should be the same, right? For models that use ResNet50 as backbone the new computation gives the same result as the previous computation. The difference would occur for models that play with the padding or strides differently. |
Yeah it should be, but the 0.350 mAP score from before was basically luck. I never succeeded in reproducing that exact score ;) a score of 0.34 is fine, but there was only one snapshot that reached 0.350. |
Is there a reason why you are not using seeds for training? |
Very good question: no there's not :D Too late now ;) |
😢 Would it be worth creating a PR which allows users to set seeds using a parameter and by default they aren't set? |
Yeah, I would think it can be useful, definitely. |
I've started training from scratch, but after a while the training stopped improving (achieved around 0.27 mAP). I've restarted training multiple times (starting from the weights of the previous iteration) and have pushed the mAP to 0.292 so far. This annoys me a bit because it suggests that the training procedure is not working properly (which I've known for a while now). Perhaps a different learning rate scheduler, or different optimizer, or both? I don't have time to look into these settings, so if someone wants to help then it is much appreciated. Until then, I'll keep restarting training after it stagnated and see how far we get :) |
For the record, this PR is still valid, but I haven't got the time to properly train a new model that gets similar accuracy as the current model. |
Have a question about this PR. Could this PR potentially improve models accuracy after we additionally train them with correct data? |
I would suspect, considering it's only off by a few pixels, that the network learns to compensate for this offset. Meaning it shouldn't matter much. On the other hand, the amount of offset is affected by the image size so it is never a constant offset, which could confuse the network. Bottom line, I don't know :)
…________________________________
From: ZFTurbo <[email protected]>
Sent: Thursday, October 31, 2019 7:16:14 AM
To: fizyr/keras-retinanet <[email protected]>
Cc: Hans Gaiser <[email protected]>; Mention <[email protected]>
Subject: Re: [fizyr/keras-retinanet] WIP: Correct computing offset of anchors. (#1075)
Have a question about this PR. Could this PR potentially improve models accuracy after we additionally train them with correct data?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#1075?email_source=notifications&email_token=AAFO22XQUI3XUNCLIQSX6PDQRJZ25A5CNFSM4IEO2X62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECWVSDQ#issuecomment-548231438>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAFO22XLRONVXLY3XA5KV33QRJZ25ANCNFSM4IEO2X6Q>.
|
This PR fixes the computation of the offset of the anchors, thanks to @jonilaserson . This PR fixes #1073 .
This affects all networks trained before this change. They should be retrained after this is merged for it to work with the latest version.
ps. I think we should hold off merging this, until we have a retrained version of the COCO weights.