Crates.io | fashion-clip-rs |
lib.rs | fashion-clip-rs |
version | 0.1.5 |
source | src |
created_at | 2023-12-13 17:52:03.543367 |
updated_at | 2023-12-23 23:27:11.098534 |
description | A complete(grpc service and lib) Rust inference with multilingual embedding support. This version leverages the power of Rust for both GRPC services and as a standalone library, providing highly efficient text and image embeddings for fashion. |
homepage | |
repository | https://github.com/yaman/fashion-clip-rs |
max_upload_size | |
id | 1068238 |
size | 894,517 |
fashion-clip-rs is the onnx ready version of fashion-clip transformers model entirely written in Rust with the help of pykeio/ort. It imports an ONNX file (at the moment, the Fashion-Clip PyTorch library from Hugging Face with an optimum CLI to convert it to ONNX format), creates a gRPC service API to create either text or image embeddings using the Fashion-Clip model and clip-ViT-B-32-multilingual-v1, runs inference for the given text or image, and returns the output vectors as a gRPC response.
fashion-clip-rs provides highly efficient text and image embeddings especially for fashion with multilingual capability.
This project can be used as a standalone library to include rust projects.
sentence-transformers/clip-ViT-B-32-multilingual-v1
.patrickjohncyh/fashion-clip
.ghz.sh
.pykeio/ort
Crate: For model loading and inference.Ensure you have the following installed:
git clone https://github.com/yaman/fashion-clip-rs.git
cd fashion-clip-rs
just build
To use the Fashion-Clip model and clip-ViT-B-32-multilingual-v1 with fashion-clip-rs, you need to convert it to ONNX format using the Hugging Face Optimum tool.
python -m pip install optimum[onnxruntime]@git+https://github.com/huggingface/optimum.git transformers sentence-transformers
optimum-cli export onnx -m sentence-transformers/clip-ViT-B-32-multilingual-v1 --task feature-extraction models/text
optimum-cli export onnx -m patrickjohncyh/fashion-clip --task feature-extraction models/image
Note 1: Accurate exporting of clip-ViT-B-32-multilingual-v1 depends on latest version of optimum. So, do not skip first step even if you have already optimum installed
Note 2: At the moment, we are using clip-ViT-B-32-multilingual-v1 to generate text embeddings. fashion-clip to generate image embeddings.
just build
just build-docker
just run
just run-docker
just unit-test
just integration-test
just coverage
just perf-test-for-text
Github action pushes to yaman/fashion-clip-rs docker hub repo everytime a change on necessary files happens. Linux/amd64 and Linux/arm64 images will be created. You can directly run image via:
docker run -v ./models:/models -v ./config.toml:/config.toml yaman/fashion-clip-rs:latest
fashion-clip-rs can also be used as a library in Rust projects.
Note: models must be ready under models/text and models/image directories. Check Model Export section
Add library to your project:
cargo add fashion_clip_rs
given model is exported to onnx with following model structure under models/text:
config.json
model.onnx
special_tokens_map.json
tokenizer_config.json
tokenizer.json
vocab.txt
use fashion_clip_rs::{config::Config, embed::EmbedText};
let embed_text = EmbedText::new(&"models/text/model.onnx", &"sentence-transformers/clip-ViT-B-32-multilingual-v1").expect("msg");
let query_embedding = embed_text.encode(&"this is a sentence".to_string());
The gRPC service provides two methods:
Encodes a text input using the Fashion-Clip model.
Request:
message TextRequest {
string text = 1;
}
Response:
message EncoderResponse {
repeated float embedding = 3;
}
Encodes an image input using the Fashion-Clip model.
Request:
message ImageRequest {
bytes image = 2;
}
Response:
message EncoderResponse {
repeated float embedding = 3;
}
Fork the repository
Create a new branch: git checkout -b feature-name
Make your changes and commit them: git commit -am 'Add some feature'
Push to the branch: git push origin feature-name
Submit a pull request
This project is licensed under the MIT License - see the LICENSE.md file for details.
For questions or feedback, please reach out to yaman.
This project was created by Yaman.