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

how to modify anchor box? #421

Closed
cjt222 opened this issue Apr 23, 2018 · 4 comments
Closed

how to modify anchor box? #421

cjt222 opened this issue Apr 23, 2018 · 4 comments

Comments

@cjt222
Copy link

cjt222 commented Apr 23, 2018

hello,i want to modify ratio of anchor(i need 7 ratio),but when i modify anchor in util/anchor.py,it cause some problem,what parameters should i modily?
image

@hgaiser
Copy link
Contributor

hgaiser commented Apr 23, 2018

Currently there is no easy method to configure this (see #324). Anchors are generated in two places unfortunately, once for creating the target data (which is the one you edited) and once for inference, which is the one you didn't edit: https://github.com/fizyr/keras-retinanet/blob/master/keras_retinanet/layers/_misc.py#L31-L45

@cjt222
Copy link
Author

cjt222 commented Apr 23, 2018

thank you for your answer, i have also changed number of anchors in keras_retinanet/vim keras_retinanet/models/retinanet.py,it is ok!!!
image

@hgaiser
Copy link
Contributor

hgaiser commented Apr 23, 2018

Ah that would work for training, but it would still break when doing inference. It reminded me that my previous comment was wrong though, for inference it is better to create an AnchorParameters object like this :

anchor_parameters = keras_retinanet.models.retinanet.AnchorParameters(
    sizes   = [32, 64, 128, 256, 512],
    strides = [8, 16, 32, 64, 128],
    ratios  = np.array([0.5, 1, 2], keras.backend.floatx()),  # Change this for your ratios
    scales  = np.array([2 ** 0, 2 ** (1.0 / 3.0), 2 ** (2.0 / 3.0)], keras.backend.floatx()),  # Change this for your scales
)

Which you then should be able to pass to this line like so:

 model = model_with_weights(backbone_retinanet(num_classes, backbone=backbone, modifier=modifier, anchor_parameters=anchor_parameters), weights=weights, skip_mismatch=True)

I haven't tried this yet though, so I don't know if it works or not..

@hgaiser hgaiser changed the title how to modify anchor box? how to modify anchor box? Apr 23, 2018
@cjt222
Copy link
Author

cjt222 commented Apr 24, 2018

ok, i see, thank you so much!!!!

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

No branches or pull requests

2 participants