【发布时间】:2019-07-15 03:48:18
【问题描述】:
我将模型加载到 tensorflow.js 中以对图像进行分类,但它返回:
"Unable to get property 'length' of undefined or null reference", message: "Unable to get property 'length' of undefined or null reference", number: -2146823281, stack: "TypeError: Unable to get property 'length' of undefined or null reference at Anonymous function(https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter:17:131397)
我使用的浏览器是chrome,模型是通过python中的tensorflow获取的
这是我的导入
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"> </script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter">`</script>
这是我的代码
<script>
const MODEL_URL = './tensorflowjs_model.pb'
const WEIGHTS_URL = './weights_manifest.json'
const INPUT_NODE_NAME = 'x';
const OUTPUT_NODE_NAME = 'prediction';
const PREPROCESS_DIVISOR = tf.scalar(255);
const foot=document.getElementById('foot')
async function fun() {
const resultElement=document.getElementById('result')
resultElement.innerText = 'Loading MobileNet...'
const model=await tf.loadFrozenModel(MODEL_URL, WEIGHTS_URL)
const pixels = tf.browser.fromPixels(foot);
var preprocessedInput = tf.div(pixels.asType('float32'), PREPROCESS_DIVISOR);
reshapedInput=tf.image.resizeNearestNeighbor(preprocessedInput,[28,28])
reshapedInput=reshapedInput.reshape([-1,28,28,3])
try{
var output;
output=model.predict({x:reshapedInput,keep_prob:1.0},OUTPUT_NODE_NAME)
console.log(output)
}
catch(err){
console.log(err)
}
console.log("hello")
};
fun()
我哪里做错了?由于截止日期快到了,我真的需要帮助... 谢谢!
【问题讨论】:
-
是不是在转换模型的时候或者上面代码的执行过程中出现了错误?
标签: model tensorflow.js