iT邦幫忙

2022 iThome 鐵人賽

DAY 28
0
Software Development

大閘蟹料理指南(rust)系列 第 28

[D28] Webassembly 進階實作

  • 分享至 

  • xImage
  •  

`
use wasm_bindgen::prelude::;
use tch::vision::imagenet;
use anyhow::{bail, Result};
use tch::
;

#[wasm_bindgen]
pub fn input() -> anyhow::Result {

let image_file = "/Users/chester/PycharmProjects/Gobblet/playground/img/img.png".to_owned();
let model_file = "/Users/chester/PycharmProjects/Gobblet/wasm_lab/model.pt".to_owned();
let image = imagenet::load_image_and_resize(image_file,224,224)?;
let model = tch::CModule::load(model_file)?;
let output = model.forward_ts(&[image.unsqueeze(0)])?.softmax(-1,tch::Kind::Float);
let binding = imagenet::top(&output, 5)
    .iter()
    .map(|(probability, class)| format!("{:50} {:5.2}%", class, 100.0 * probability))
    .collect::<Vec<_>>()
    .join(" ");
Ok(binding)

}
`

place holder


上一篇
[D27] WebAssembly
下一篇
[D29]Rust CI CD
系列文
大閘蟹料理指南(rust)30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言