mirror of
https://github.com/mii443/usls.git
synced 2025-08-22 15:45:41 +00:00
Add RF-DETR large model (#87)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use aksr::Builder;
|
||||
|
||||
use crate::{InstanceMeta, Keypoint, Style};
|
||||
use crate::{impl_meta_methods, InstanceMeta, Keypoint, Style};
|
||||
|
||||
#[derive(Builder, Clone, Default)]
|
||||
pub struct Hbb {
|
||||
@ -83,44 +83,8 @@ impl From<Hbb> for [f32; 4] {
|
||||
}
|
||||
|
||||
impl Hbb {
|
||||
pub fn with_uid(mut self, uid: usize) -> Self {
|
||||
self.meta = self.meta.with_uid(uid);
|
||||
self
|
||||
}
|
||||
impl_meta_methods!();
|
||||
|
||||
pub fn with_id(mut self, id: usize) -> Self {
|
||||
self.meta = self.meta.with_id(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.meta = self.meta.with_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_confidence(mut self, confidence: f32) -> Self {
|
||||
self.meta = self.meta.with_confidence(confidence);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn uid(&self) -> usize {
|
||||
self.meta.uid()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.meta.name()
|
||||
}
|
||||
|
||||
pub fn confidence(&self) -> Option<f32> {
|
||||
self.meta.confidence()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<usize> {
|
||||
self.meta.id()
|
||||
}
|
||||
}
|
||||
|
||||
impl Hbb {
|
||||
pub fn from_xywh(x: f32, y: f32, w: f32, h: f32) -> Self {
|
||||
Self {
|
||||
x,
|
||||
|
@ -77,3 +77,37 @@ impl InstanceMeta {
|
||||
label
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_meta_methods {
|
||||
() => {
|
||||
pub fn with_uid(mut self, uid: usize) -> Self {
|
||||
self.meta = self.meta.with_uid(uid);
|
||||
self
|
||||
}
|
||||
pub fn with_id(mut self, id: usize) -> Self {
|
||||
self.meta = self.meta.with_id(id);
|
||||
self
|
||||
}
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.meta = self.meta.with_name(name);
|
||||
self
|
||||
}
|
||||
pub fn with_confidence(mut self, confidence: f32) -> Self {
|
||||
self.meta = self.meta.with_confidence(confidence);
|
||||
self
|
||||
}
|
||||
pub fn uid(&self) -> usize {
|
||||
self.meta.uid()
|
||||
}
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.meta.name()
|
||||
}
|
||||
pub fn confidence(&self) -> Option<f32> {
|
||||
self.meta.confidence()
|
||||
}
|
||||
pub fn id(&self) -> Option<usize> {
|
||||
self.meta.id()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use aksr::Builder;
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
|
||||
use crate::{InstanceMeta, Style};
|
||||
use crate::{impl_meta_methods, InstanceMeta, Style};
|
||||
|
||||
/// Represents a keypoint in a 2D space with optional metadata.
|
||||
#[derive(Builder, Default, Clone)]
|
||||
@ -69,44 +69,8 @@ impl From<Keypoint> for [f32; 2] {
|
||||
}
|
||||
|
||||
impl Keypoint {
|
||||
pub fn with_uid(mut self, uid: usize) -> Self {
|
||||
self.meta = self.meta.with_uid(uid);
|
||||
self
|
||||
}
|
||||
impl_meta_methods!();
|
||||
|
||||
pub fn with_id(mut self, id: usize) -> Self {
|
||||
self.meta = self.meta.with_id(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.meta = self.meta.with_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_confidence(mut self, confidence: f32) -> Self {
|
||||
self.meta = self.meta.with_confidence(confidence);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn uid(&self) -> usize {
|
||||
self.meta.uid()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.meta.name()
|
||||
}
|
||||
|
||||
pub fn confidence(&self) -> Option<f32> {
|
||||
self.meta.confidence()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<usize> {
|
||||
self.meta.id()
|
||||
}
|
||||
}
|
||||
|
||||
impl Keypoint {
|
||||
pub fn new(x: f32, y: f32) -> Self {
|
||||
Self {
|
||||
x,
|
||||
|
@ -3,7 +3,7 @@ use anyhow::Result;
|
||||
use image::GrayImage;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::{InstanceMeta, Polygon, Style};
|
||||
use crate::{impl_meta_methods, InstanceMeta, Polygon, Style};
|
||||
|
||||
/// Mask: Gray Image.
|
||||
#[derive(Builder, Default, Clone)]
|
||||
@ -35,6 +35,7 @@ impl PartialEq for Mask {
|
||||
}
|
||||
|
||||
impl Mask {
|
||||
impl_meta_methods!();
|
||||
pub fn new(u8s: &[u8], width: u32, height: u32) -> Result<Self> {
|
||||
let mask: image::ImageBuffer<image::Luma<_>, Vec<_>> =
|
||||
image::ImageBuffer::from_raw(width, height, u8s.to_vec())
|
||||
@ -103,40 +104,3 @@ impl Mask {
|
||||
polygons
|
||||
}
|
||||
}
|
||||
|
||||
impl Mask {
|
||||
pub fn with_uid(mut self, uid: usize) -> Self {
|
||||
self.meta = self.meta.with_uid(uid);
|
||||
self
|
||||
}
|
||||
pub fn with_id(mut self, id: usize) -> Self {
|
||||
self.meta = self.meta.with_id(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.meta = self.meta.with_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_confidence(mut self, confidence: f32) -> Self {
|
||||
self.meta = self.meta.with_confidence(confidence);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn uid(&self) -> usize {
|
||||
self.meta.uid()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.meta.name()
|
||||
}
|
||||
|
||||
pub fn confidence(&self) -> Option<f32> {
|
||||
self.meta.confidence()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<usize> {
|
||||
self.meta.id()
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use aksr::Builder;
|
||||
|
||||
use crate::{Hbb, InstanceMeta, Keypoint, Polygon, Style};
|
||||
use crate::{impl_meta_methods, Hbb, InstanceMeta, Keypoint, Polygon, Style};
|
||||
|
||||
#[derive(Builder, Default, Clone, PartialEq)]
|
||||
pub struct Obb {
|
||||
@ -48,6 +48,7 @@ impl From<Obb> for [[f32; 2]; 4] {
|
||||
}
|
||||
|
||||
impl Obb {
|
||||
impl_meta_methods!();
|
||||
/// Build from (cx, cy, width, height, degrees)
|
||||
pub fn from_cxcywhd(cx: f32, cy: f32, w: f32, h: f32, d: f32) -> Self {
|
||||
Self::from_cxcywhr(cx, cy, w, h, d.to_radians())
|
||||
@ -142,43 +143,6 @@ impl Obb {
|
||||
}
|
||||
}
|
||||
|
||||
impl Obb {
|
||||
pub fn with_uid(mut self, uid: usize) -> Self {
|
||||
self.meta = self.meta.with_uid(uid);
|
||||
self
|
||||
}
|
||||
pub fn with_id(mut self, id: usize) -> Self {
|
||||
self.meta = self.meta.with_id(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.meta = self.meta.with_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_confidence(mut self, confidence: f32) -> Self {
|
||||
self.meta = self.meta.with_confidence(confidence);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn uid(&self) -> usize {
|
||||
self.meta.uid()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.meta.name()
|
||||
}
|
||||
|
||||
pub fn confidence(&self) -> Option<f32> {
|
||||
self.meta.confidence()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<usize> {
|
||||
self.meta.id()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests_mbr {
|
||||
// use crate::Nms;
|
||||
|
@ -4,7 +4,7 @@ use geo::{
|
||||
Point, Simplify,
|
||||
};
|
||||
|
||||
use crate::{Hbb, InstanceMeta, Mask, Obb, Style};
|
||||
use crate::{impl_meta_methods, Hbb, InstanceMeta, Mask, Obb, Style};
|
||||
|
||||
/// Polygon.
|
||||
#[derive(Builder, Clone)]
|
||||
@ -43,6 +43,7 @@ impl PartialEq for Polygon {
|
||||
}
|
||||
|
||||
impl Polygon {
|
||||
impl_meta_methods!();
|
||||
pub fn with_points_imageproc(mut self, points: &[imageproc::point::Point<i32>]) -> Self {
|
||||
// exterior
|
||||
let v = points
|
||||
@ -245,40 +246,3 @@ impl Polygon {
|
||||
xs.retain(|point| seen.insert((point.x() as i32, point.y() as i32)));
|
||||
}
|
||||
}
|
||||
|
||||
impl Polygon {
|
||||
pub fn with_uid(mut self, uid: usize) -> Self {
|
||||
self.meta = self.meta.with_uid(uid);
|
||||
self
|
||||
}
|
||||
pub fn with_id(mut self, id: usize) -> Self {
|
||||
self.meta = self.meta.with_id(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.meta = self.meta.with_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_confidence(mut self, confidence: f32) -> Self {
|
||||
self.meta = self.meta.with_confidence(confidence);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn uid(&self) -> usize {
|
||||
self.meta.uid()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.meta.name()
|
||||
}
|
||||
|
||||
pub fn confidence(&self) -> Option<f32> {
|
||||
self.meta.confidence()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<usize> {
|
||||
self.meta.id()
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use aksr::Builder;
|
||||
|
||||
use crate::{InstanceMeta, Style};
|
||||
use crate::{impl_meta_methods, InstanceMeta, Style};
|
||||
|
||||
#[derive(Builder, Clone, PartialEq, Default, Debug)]
|
||||
pub struct Prob {
|
||||
@ -12,6 +12,7 @@ pub struct Prob {
|
||||
// pub struct Probs(#[args(aka = "probs")] Vec<Prob>);
|
||||
|
||||
impl Prob {
|
||||
impl_meta_methods!();
|
||||
pub fn new_probs(probs: &[f32], names: Option<&[&str]>, k: usize) -> Vec<Self> {
|
||||
let mut pairs: Vec<(usize, f32)> = probs
|
||||
.iter()
|
||||
@ -39,40 +40,4 @@ impl Prob {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn with_uid(mut self, uid: usize) -> Self {
|
||||
self.meta = self.meta.with_uid(uid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: usize) -> Self {
|
||||
self.meta = self.meta.with_id(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.meta = self.meta.with_name(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_confidence(mut self, confidence: f32) -> Self {
|
||||
self.meta = self.meta.with_confidence(confidence);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn uid(&self) -> usize {
|
||||
self.meta.uid()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.meta.name()
|
||||
}
|
||||
|
||||
pub fn confidence(&self) -> Option<f32> {
|
||||
self.meta.confidence()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<usize> {
|
||||
self.meta.id()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user