mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 02:58:50 +00:00
Use the hub to retrieve dinov2 model weights. (#507)
This commit is contained in:
@ -28,7 +28,10 @@ Check out our [examples](./candle-examples/examples/):
|
|||||||
- [StarCoder](./candle-examples/examples/bigcode/): LLM specialized to code
|
- [StarCoder](./candle-examples/examples/bigcode/): LLM specialized to code
|
||||||
generation.
|
generation.
|
||||||
- [Stable Diffusion](./candle-examples/examples/stable-diffusion/): text to
|
- [Stable Diffusion](./candle-examples/examples/stable-diffusion/): text to
|
||||||
image generative model, yet to be optimized.
|
image generative model.
|
||||||
|
- [DINOv2](./candle-examples/examples/dinov2/): computer vision model trained
|
||||||
|
using self-supervision (can be used for imagenet classification, depth
|
||||||
|
evaluation, segmentation).
|
||||||
|
|
||||||
Run them using the following commands:
|
Run them using the following commands:
|
||||||
```
|
```
|
||||||
@ -38,6 +41,7 @@ cargo run --example falcon --release
|
|||||||
cargo run --example bert --release
|
cargo run --example bert --release
|
||||||
cargo run --example bigcode --release
|
cargo run --example bigcode --release
|
||||||
cargo run --example stable-diffusion --release -- --prompt "a rusty robot holding a fire torch"
|
cargo run --example stable-diffusion --release -- --prompt "a rusty robot holding a fire torch"
|
||||||
|
cargo run --example dinov2 --release -- --image path/to/myinput.jpg
|
||||||
```
|
```
|
||||||
|
|
||||||
In order to use **CUDA** add `--features cuda` to the example command line. If
|
In order to use **CUDA** add `--features cuda` to the example command line. If
|
||||||
@ -75,6 +79,7 @@ And then head over to
|
|||||||
- LLMs: Llama v1 and v2, Falcon, StarCoder.
|
- LLMs: Llama v1 and v2, Falcon, StarCoder.
|
||||||
- Whisper (multi-lingual support).
|
- Whisper (multi-lingual support).
|
||||||
- Stable Diffusion.
|
- Stable Diffusion.
|
||||||
|
- Computer Vision: DINOv2.
|
||||||
- Serverless (on CPU), small and fast deployments.
|
- Serverless (on CPU), small and fast deployments.
|
||||||
- Quantization support using the llama.cpp quantized types.
|
- Quantization support using the llama.cpp quantized types.
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ pub fn vit_small(vb: VarBuilder) -> Result<DinoVisionTransformer> {
|
|||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
model: String,
|
model: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
image: String,
|
image: String,
|
||||||
@ -309,7 +309,15 @@ pub fn main() -> anyhow::Result<()> {
|
|||||||
let image = candle_examples::load_image224(args.image)?;
|
let image = candle_examples::load_image224(args.image)?;
|
||||||
println!("loaded image {image:?}");
|
println!("loaded image {image:?}");
|
||||||
|
|
||||||
let weights = unsafe { candle::safetensors::MmapedFile::new(args.model)? };
|
let model_file = match args.model {
|
||||||
|
None => {
|
||||||
|
let api = hf_hub::api::sync::Api::new()?;
|
||||||
|
let api = api.model("lmz/candle-dino-v2".into());
|
||||||
|
api.get("dinov2_vits14.safetensors")?
|
||||||
|
}
|
||||||
|
Some(model) => model.into(),
|
||||||
|
};
|
||||||
|
let weights = unsafe { candle::safetensors::MmapedFile::new(model_file)? };
|
||||||
let weights = weights.deserialize()?;
|
let weights = weights.deserialize()?;
|
||||||
let vb = VarBuilder::from_safetensors(vec![weights], DType::F32, &device);
|
let vb = VarBuilder::from_safetensors(vec![weights], DType::F32, &device);
|
||||||
let model = vit_small(vb)?;
|
let model = vit_small(vb)?;
|
||||||
|
Reference in New Issue
Block a user