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

Features "successfully extracted", but not? #182

Open
jibrjabr opened this issue Nov 19, 2024 · 5 comments
Open

Features "successfully extracted", but not? #182

jibrjabr opened this issue Nov 19, 2024 · 5 comments

Comments

@jibrjabr
Copy link

Haven't used THINGSvision in a while (last time thingsvision.vision was still a thing) so I updated to the latest version to extract feature values for some images. I am doing this in vscode with output appearing in an interactive window. Everything seems to run fine (just copying and pasting the tutorial code and specifying the image and output directories) until I try extracting the feature weights (for vgg16_bn):

module_name= 'features.23'
features = extractor.extract_features(
batches=batches,
module_name=module_name,
flatten_acts=True,
output_type="ndarray", # or "tensor" (only applicable to PyTorch models)
)

The cell of code is seemingly executed successfully (little green "success" check mark in the interactive window). And I get the usual message saying that the features have been successfully extracted.

"...Features successfully extracted for all 16 images in the database."

However, there is no variable "features" that is generated as output. And if I try to execute anything else I get the pending clock. I then noticed that some of the cell output text was invisible for some reason and says:

"Batch: 0%| | 0/1 [00:00<?, ?it/s]"

So maybe something didn't execute correctly? Never had any issue with the older version so would appreciate any suggestions of what's going on (I assume it's something on my end).

@LukasMut
Copy link
Collaborator

What's your batch size?

@jibrjabr
Copy link
Author

Batch_size = 32

@LukasMut
Copy link
Collaborator

Could you try 8 or 16 and report back?

@jibrjabr
Copy link
Author

I set batch_size = 16, 8, 4, 2. Not sure if it matters, but this results in the DataLoader "batches" having size 1,2,4,16, respectively. All produce the same behavior. For reference when I had used the old version (without issue) batch_size = 64.

@jibrjabr
Copy link
Author

Another update, I ran this instead (also taken directly from your documentation):

with extractor.batch_extraction(module_name, output_type="ndarray") as e:
for batch in batches:
feature_batch = e.extract_batch(
batch=batch,
flatten_acts=True, # flatten 2D feature maps from an early convolutional or attention layer
)

And I got the correct output (batch_size = 16); namely, an ndarray that was 16 x flattened features.

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