mirror of
https://github.com/huggingface/candle.git
synced 2025-06-22 12:28:06 +00:00
Add a yolo-v3 example. (#528)
* Add a couple functions required for yolo. * Add the yolo-v3 example. * Add minimum and maximum. * Use the newly introduced maximum. * Cuda support for min/max + add some testing. * Allow for more tests to work with accelerate. * Fix a typo.
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
#[cfg(feature = "mkl")]
|
||||
extern crate intel_mkl_src;
|
||||
|
||||
#[cfg(feature = "accelerate")]
|
||||
extern crate accelerate_src;
|
||||
|
||||
use candle::{DType, Device, Result, Tensor};
|
||||
use candle_nn::{linear, AdamW, Linear, Module, ParamsAdamW, VarBuilder, VarMap};
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
#[cfg(feature = "mkl")]
|
||||
extern crate intel_mkl_src;
|
||||
|
||||
#[cfg(feature = "accelerate")]
|
||||
extern crate accelerate_src;
|
||||
|
||||
mod test_utils;
|
||||
|
||||
use anyhow::Result;
|
||||
|
@ -21,6 +21,9 @@ print(group_norm(t, num_groups=3))
|
||||
#[cfg(feature = "mkl")]
|
||||
extern crate intel_mkl_src;
|
||||
|
||||
#[cfg(feature = "accelerate")]
|
||||
extern crate accelerate_src;
|
||||
|
||||
use anyhow::Result;
|
||||
use candle::{Device, Tensor};
|
||||
use candle_nn::{GroupNorm, Module};
|
||||
|
@ -1,10 +1,15 @@
|
||||
#[cfg(feature = "mkl")]
|
||||
extern crate intel_mkl_src;
|
||||
|
||||
#[cfg(feature = "accelerate")]
|
||||
extern crate accelerate_src;
|
||||
|
||||
use anyhow::Result;
|
||||
use candle::{Device, Tensor};
|
||||
use candle_nn::{LayerNorm, Module};
|
||||
|
||||
mod test_utils;
|
||||
|
||||
#[test]
|
||||
fn layer_norm() -> Result<()> {
|
||||
let device = &Device::Cpu;
|
||||
@ -23,11 +28,11 @@ fn layer_norm() -> Result<()> {
|
||||
let inp = Tensor::new(&[[[1f32, 2., 3.], [4., 5., 6.], [9., 8., 7.]]], device)?;
|
||||
let res = ln.forward(&inp)?;
|
||||
assert_eq!(
|
||||
res.to_vec3::<f32>()?,
|
||||
test_utils::to_vec3_round(res.clone(), 4)?,
|
||||
[[
|
||||
[-3.1742344, 0.5, 4.1742344],
|
||||
[-3.1742344, 0.5, 4.1742344],
|
||||
[4.1742344, 0.5, -3.1742344]
|
||||
[-3.1742, 0.5, 4.1742],
|
||||
[-3.1742, 0.5, 4.1742],
|
||||
[4.1742, 0.5, -3.1742]
|
||||
]]
|
||||
);
|
||||
let mean = (res.sum_keepdim(2)? / 3.0)?;
|
||||
@ -36,8 +41,8 @@ fn layer_norm() -> Result<()> {
|
||||
let std = (res.broadcast_sub(&mean)?.sqr()?.sum_keepdim(2)?.sqrt()? / 3.0)?;
|
||||
// The standard deviation should be sqrt(`w`).
|
||||
assert_eq!(
|
||||
std.to_vec3::<f32>()?,
|
||||
[[[1.7320508], [1.7320508], [1.7320508]]]
|
||||
test_utils::to_vec3_round(std, 4)?,
|
||||
[[[1.7321], [1.7321], [1.7321]]]
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
#[cfg(feature = "mkl")]
|
||||
extern crate intel_mkl_src;
|
||||
|
||||
#[cfg(feature = "accelerate")]
|
||||
extern crate accelerate_src;
|
||||
|
||||
use candle::{Device, Result, Tensor};
|
||||
mod test_utils;
|
||||
use test_utils::to_vec0_round;
|
||||
|
@ -1,6 +1,9 @@
|
||||
#[cfg(feature = "mkl")]
|
||||
extern crate intel_mkl_src;
|
||||
|
||||
#[cfg(feature = "accelerate")]
|
||||
extern crate accelerate_src;
|
||||
|
||||
mod test_utils;
|
||||
use test_utils::to_vec3_round;
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
#[cfg(feature = "mkl")]
|
||||
extern crate intel_mkl_src;
|
||||
|
||||
#[cfg(feature = "accelerate")]
|
||||
extern crate accelerate_src;
|
||||
|
||||
mod test_utils;
|
||||
use test_utils::{to_vec0_round, to_vec2_round};
|
||||
|
||||
|
Reference in New Issue
Block a user