Return the low res mask in the wasm segment-anything module. (#798)

* Return the low res mask.

* Add some validations.
This commit is contained in:
Laurent Mazare
2023-09-10 13:03:02 +01:00
committed by GitHub
parent 584171cae1
commit 90e077e409
2 changed files with 20 additions and 10 deletions

View File

@ -77,8 +77,18 @@ impl Model {
// x and y have to be between 0 and 1
pub fn mask_for_point(&self, x: f64, y: f64) -> Result<String, JsError> {
if !(0. ..=1.).contains(&x) {
Err(JsError::new(&format!(
"x has to be between 0 and 1, got {x}"
)))?
}
if !(0. ..=1.).contains(&y) {
Err(JsError::new(&format!(
"y has to be between 0 and 1, got {y}"
)))?
}
let embeddings = match &self.embeddings {
None => todo!(),
None => Err(JsError::new("image embeddings have not been set"))?,
Some(embeddings) => embeddings,
};
let (mask, iou_predictions) = self.sam.forward_for_embeddings(