Skip to content

Instantly share code, notes, and snippets.

@juntao
Created February 24, 2021 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juntao/2ffac70d9e4c9334708bb4e83e6e1599 to your computer and use it in GitHub Desktop.
Save juntao/2ffac70d9e4c9334708bb4e83e6e1599 to your computer and use it in GitHub Desktop.
// Load the model data from a file
let model_data: &[u8] = include_bytes!("lite-model_aiy_vision_classifier_food_V1_1.tflite");
// Read the input image data from Tencent Cloud's API gateway
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).expect("Error reading from STDIN");
let obj: FaasInput = serde_json::from_str(&buffer).unwrap();
let img_buf = base64::decode_config(&(obj.body), base64::STANDARD).unwrap();
// Resize the image to the size needed by the Tensorflow model
let flat_img = ssvm_tensorflow_interface::load_jpg_image_to_rgb8(&img_buf, 192, 192);
// Execute the model against the input image and gets the result tensor value
let mut session = ssvm_tensorflow_interface::Session::new(&model_data, ssvm_tensorflow_interface::ModelType::TensorFlowLite);
session.add_input("input", &flat_img, &[1, 192, 192, 3]).run();
let res_vec: Vec<u8> = session.get_output("MobilenetV1/Predictions/Softmax");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment