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

Access to intermediate layer TridentNet #285

Open
simaiden opened this issue Dec 28, 2019 · 6 comments
Open

Access to intermediate layer TridentNet #285

simaiden opened this issue Dec 28, 2019 · 6 comments

Comments

@simaiden
Copy link

I want to access to an intermediate layer of TridentNet to get a feature vector, in particular feature vector after doing the roi pool operation, how can i perform this?

Thanks

@RogerChern
Copy link
Collaborator

Our wrapper library mxnext provides a mxnext.foward_debug operator that accepts a callback with signature callback(gpu_id, num_iter, *data).

You can add the following to your Head

def save_roi_feat(gpu_id, num_iter, roi_feat):
    if gpu_id == 0 and num_iter + 1 % 100 == 0:
        np.save("trident_roi_feature_%d" % int(num_iter), roi_feat)

roi_feat = X.forward_debug(roi_feat, callback=save_roi_feat)

@simaiden
Copy link
Author

Thanks for reply! Sorry about the dumb question but is RpnHead the Head
intridentnet_r50v2c4_c5_1x.py ? or may I have to save roi_extractor = RoiExtractor(RoiParam)?

Thanks in advance

@RogerChern
Copy link
Collaborator

I think that inserting the hook at the input of BboxC5Head may be a good idea.

https://github.com/TuSimple/simpledet/blob/f67fca08b33d957b43eb1db5e3745a3a9e3803b5/symbol/builder.py#L558-L579

You can put the following snippet in just before L564

def save_roi_feat(gpu_id, num_iter, roi_feat):
    if gpu_id == 0 and num_iter + 1 % 100 == 0:
        import numpy as np
        np.save("trident_roi_feature_%d" % int(num_iter), roi_feat)

conv_feat = X.forward_debug(conv_feat, callback=save_roi_feat)

And you can find trident_roi_feat_XXX.npy in your directory.

@simaiden
Copy link
Author

simaiden commented Jan 1, 2020

I have an error:

RuntimeError: num_iter_b5f728d4-dac5-4563-be3a-0a3f8a5c690a is not presented

Maybe the code you posted ir just for training? How can i get the roi feats in inference?

Thanks!

@RogerChern
Copy link
Collaborator

RogerChern commented Jan 2, 2020 via email

@simaiden
Copy link
Author

simaiden commented Jan 2, 2020

Thanks @RogerChern , I'll give a try

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