onnxruntime/download/vision/image_manipulation.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
//! Module defining image manipulation models available to download.
//!
//! See [https://github.com/onnx/models#image_manipulation](https://github.com/onnx/models#image_manipulation)
use crate::download::{vision::Vision, AvailableOnnxModel, ModelUrl};
/// Image Manipulation
///
/// > Image manipulation models use neural networks to transform input images to modified output images. Some
/// > popular models in this category involve style transfer or enhancing images by increasing resolution.
///
/// Source: [https://github.com/onnx/models#image_manipulation](https://github.com/onnx/models#image_manipulation)
#[derive(Debug, Clone)]
pub enum ImageManipulation {
/// Super Resolution
///
/// > The Super Resolution machine learning model sharpens and upscales the input image to refine the
/// > details and improve quality.
///
/// Source: [https://github.com/onnx/models/tree/master/vision/super_resolution/sub_pixel_cnn_2016](https://github.com/onnx/models/tree/master/vision/super_resolution/sub_pixel_cnn_2016)
///
/// Variant downloaded: ONNX Version 1.5 with Opset Version 10.
SuperResolution,
/// Fast Neural Style Transfer
///
/// > This artistic style transfer model mixes the content of an image with the style of another image.
/// > Examples of the styles can be seen
/// > [in this PyTorch example](https://github.com/pytorch/examples/tree/master/fast_neural_style#models).
///
/// Source: [https://github.com/onnx/models/tree/master/vision/style_transfer/fast_neural_style](https://github.com/onnx/models/tree/master/vision/style_transfer/fast_neural_style)
FastNeuralStyleTransfer(FastNeuralStyleTransferStyle),
}
/// Fast Neural Style Transfer Style
///
/// Source: [https://github.com/onnx/models/tree/master/vision/style_transfer/fast_neural_style](https://github.com/onnx/models/tree/master/vision/style_transfer/fast_neural_style)
///
/// Variant downloaded: ONNX Version 1.4 with Opset Version 9.
#[derive(Debug, Clone)]
pub enum FastNeuralStyleTransferStyle {
/// Mosaic style
Mosaic,
/// Candy style
Candy,
/// RainPrincess style
RainPrincess,
/// Udnie style
Udnie,
/// Pointilism style
Pointilism,
}
impl ModelUrl for ImageManipulation {
fn fetch_url(&self) -> &'static str {
match self {
ImageManipulation::SuperResolution => "https://github.com/onnx/models/raw/master/vision/super_resolution/sub_pixel_cnn_2016/model/super-resolution-10.onnx",
ImageManipulation::FastNeuralStyleTransfer(style) => style.fetch_url(),
}
}
}
impl ModelUrl for FastNeuralStyleTransferStyle {
fn fetch_url(&self) -> &'static str {
match self {
FastNeuralStyleTransferStyle::Mosaic => "https://github.com/onnx/models/raw/master/vision/style_transfer/fast_neural_style/model/mosaic-9.onnx",
FastNeuralStyleTransferStyle::Candy => "https://github.com/onnx/models/raw/master/vision/style_transfer/fast_neural_style/model/candy-9.onnx",
FastNeuralStyleTransferStyle::RainPrincess => "https://github.com/onnx/models/raw/master/vision/style_transfer/fast_neural_style/model/rain-princess-9.onnx",
FastNeuralStyleTransferStyle::Udnie => "https://github.com/onnx/models/raw/master/vision/style_transfer/fast_neural_style/model/udnie-9.onnx",
FastNeuralStyleTransferStyle::Pointilism => "https://github.com/onnx/models/raw/master/vision/style_transfer/fast_neural_style/model/pointilism-9.onnx",
}
}
}
impl From<ImageManipulation> for AvailableOnnxModel {
fn from(model: ImageManipulation) -> Self {
AvailableOnnxModel::Vision(Vision::ImageManipulation(model))
}
}
impl From<FastNeuralStyleTransferStyle> for AvailableOnnxModel {
fn from(style: FastNeuralStyleTransferStyle) -> Self {
AvailableOnnxModel::Vision(Vision::ImageManipulation(
ImageManipulation::FastNeuralStyleTransfer(style),
))
}
}