neuralmagic / sparsezoo

Neural network model repository for highly sparse and sparse-quantized models with matching sparsification recipes
Apache License 2.0
370 stars 25 forks source link

Feature extraction using pertained models #245

Closed siamakzd closed 1 year ago

siamakzd commented 1 year ago

Hello,

Thank you for the great library! I have a simple use case but I can't figure out how to achieve it. I want to use one of the pertained and pruned models on SparseZoo and use it as a feature extractor in my pipeline (no extra fine-tuning or pruning).

More specifically, I want to:

  1. download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95-none ,
  2. modify the model by removing the classifier head,
  3. then apply the modified model to any image to get the output pooled vector as the embedding of that image.

Is this possible? If yes, I will appreciate any pointers to the relevant documentations.

Thank you!

bfineran commented 1 year ago

Hi @siamakzd take a look our embedding extraction pipeline in deepsparse: https://github.com/neuralmagic/deepsparse/blob/main/src/deepsparse/pipelines/embedding_extraction.py

after identifying the name of a node in onnx you would like to extract the features from, you could accomplish this with

from deepsparse import Pipeline

feature_extractor = Pipeline.create(
    task="embedding-extraction",
    base_task="image-classification",
    model_path="zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95-none",
    emb_extraction_layer=<NAME OF NODE TO EXTRACT>,
)
jeanniefinks commented 1 year ago

Hello @siamakzd We have not heard a response on this issue and will close this one out. If you would like to continue the conversation, please re-open it. Thank you!

Jeannie / Neural Magic