idealo / image-quality-assessment

Convolutional Neural Networks to predict the aesthetic and technical quality of images.
https://idealo.github.io/image-quality-assessment/
Apache License 2.0
2.05k stars 441 forks source link

Can TF saved model be used to generate Web friendly model #68

Closed jeetAdhikary closed 4 years ago

jeetAdhikary commented 4 years ago

Hi , I am trying to use pre-trained tf saved model to generate web friendly model . The models are situated in contrib/tf_serving/tfs_models folder .

I have successfully converted the model using tensorflowjs_converter . and the generated format is graph model . I have tried to use this model for prediction but I am facing below error :

Error: Operands could not be broadcast together with shapes 1,112,112,32 and 0.
    at Co (tf-core.esm.js?45ef:17)
    at new ka (tf-core.esm.js?45ef:17)
    at o.batchNormalization (tf-core.esm.js?45ef:17)
    at eval (tf-core.esm.js?45ef:17)
    at eval (tf-core.esm.js?45ef:17)
    at eval (tf-core.esm.js?45ef:17)
    at t.scopedRun (tf-core.esm.js?45ef:17)
    at t.tidy (tf-core.esm.js?45ef:17)
    at f (tf-core.esm.js?45ef:17)
    at eval (tf-core.esm.js?45ef:17)

Here is the step followed :

Converted TF saved model to Web model :

tensorflowjs_converter \
    --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    --signature_name=image_quality\
    --saved_model_tags=serve \
    <saved model Location> \
    <web model location>

Loaded Model using tfjs :

const model = await tf.loadGraphModel(assets/models/aesthetic/model.json)

prediction Function :

const prediction = async (image: HTMLImageElement) => {
  const img = tf.browser
    .fromPixels(image)
    .resizeNearestNeighbor([224, 224])
    .toFload();

  let offset = tf.scalar(127.5);
  const imgTensor = img
    .sub(offset)
    .div(offset)
    .expandDims();

  const pred = await module.executeAsync(imgTensor);
  return pred;
};

Please help !

clennan commented 4 years ago

Hi, this is really a tensorflowjs specific issue and you should try to raise it with them