examples icon indicating copy to clipboard operation
examples copied to clipboard

以图搜图如何使用自己的模型

Open David1-git opened this issue 2 years ago • 13 comments

在 p_embed = ( pipe.input('src') .flat_map('src', 'img_path', load_image) .map('img_path', 'img', ops.image_decode()) .map('img', 'vec', ops.image_embedding.timm(model_name=MODEL, device=DEVICE)) ) 现在我有一个行人重识别的模型,在这里我需要怎么样做,才能替换为自己的模型。非常期待您的回复,感谢!

David1-git avatar Aug 28 '23 13:08 David1-git

If you want to pass in the weights of a PyTorch model, you can pass it in as parameter: ops.image_embedding.timm(model_name=MODEL, device=DEVICE, checkpoint_path=YOUR_WEIGHTS_PATH) If it contains PyTorch code, a new operator needs to be created. https://towhee.readthedocs.io/en/latest/operator/usage.html#run-pipeline-with-named-operators You can refer to this implementation https://towhee.io/image-embedding/timm/raw/branch/main/timm_image.py

junjiejiangjjj avatar Aug 29 '23 07:08 junjiejiangjjj

If you want to pass in the weights of a PyTorch model, you can pass it in as parameter: ops.image_embedding.timm(model_name=MODEL, device=DEVICE, checkpoint_path=YOUR_WEIGHTS_PATH) If it contains PyTorch code, a new operator needs to be created. https://towhee.readthedocs.io/en/latest/operator/usage.html#run-pipeline-with-named-operators You can refer to this implementation https://towhee.io/image-embedding/timm/raw/branch/main/timm_image.py

我可以使用timm库注册自己的模型吗

David1-git avatar Aug 29 '23 09:08 David1-git

If you want to pass in the weights of a PyTorch model, you can pass it in as parameter: ops.image_embedding.timm(model_name=MODEL, device=DEVICE, checkpoint_path=YOUR_WEIGHTS_PATH) If it contains PyTorch code, a new operator needs to be created. https://towhee.readthedocs.io/en/latest/operator/usage.html#run-pipeline-with-named-operators You can refer to this implementation https://towhee.io/image-embedding/timm/raw/branch/main/timm_image.py

我想要替换掉以图搜图里的模型,使用自己的行人重识别模型。换句话说,我想让我的行人重识别模型可以像以图搜图项目那样部署在服务器上

David1-git avatar Aug 29 '23 09:08 David1-git

https://github.com/huggingface/pytorch-image-models/tree/main/timm/models
Can you find the model you are using there? If so, you can use timm.

junjiejiangjjj avatar Aug 29 '23 09:08 junjiejiangjjj

https://github.com/huggingface/pytorch-image-models/tree/main/timm/models Can you find the model you are using there? If so, you can use timm.

这个里面没有我使用的模型

David1-git avatar Aug 29 '23 14:08 David1-git

Then you'll have to implement an op yourself.

junjiejiangjjj avatar Aug 30 '23 02:08 junjiejiangjjj

Then you'll have to implement an op yourself. 具体要怎么实现呢,可以具体说一下吗

David1-git avatar Aug 30 '23 07:08 David1-git

Then you'll have to implement an op yourself. 具体要怎么实现呢,可以具体说一下吗

https://towhee.readthedocs.io/en/latest/operator/usage.html#run-pipeline-with-named-operators

junjiejiangjjj avatar Aug 30 '23 08:08 junjiejiangjjj

@junjiejiangjjj I found that there is ConvNeXt-V2 in timm, but I use https://github.com/open-mmlab/mmpretrain or https://github.com/facebookresearch/ConvNeXt-V2 for training. You can directly use timm to load this Is it a model trained by two warehouses?

watertianyi avatar Sep 11 '24 08:09 watertianyi

@junjiejiangjjj I found that there is ConvNeXt-V2 in timm, but I use https://github.com/open-mmlab/mmpretrain or https://github.com/facebookresearch/ConvNeXt-V2 for training. You can directly use timm to load this Is it a model trained by two warehouses?

You can use checkpoint_path param to load your weights: ops.image_embedding.timm(model_name='resnet50', checkpoint_path="your weights file path")

junjiejiangjjj avatar Sep 11 '24 09:09 junjiejiangjjj

@junjiejiangjjj 2024-09-12 16-00-16 的屏幕截图 Why does the result graph when I run the same code look like this? https://github.com/towhee-io/examples/blob/afbd207d9e65798d913b8f4eff8ba355000ada84/image/reverse_image_search/1_build_image_search_engine.ipynb

watertianyi avatar Sep 12 '24 08:09 watertianyi

image This op decodes the image in bgr format by default, so the displayed image color is incorrect. Use ops.image_decode.cv2('rgb') to display it normally.

junjiejiangjjj avatar Sep 12 '24 08:09 junjiejiangjjj

@junjiejiangjjj Thank you for your prompt reply!

watertianyi avatar Sep 12 '24 09:09 watertianyi