0

Uncaught ReferenceError当我尝试加载这个脚本时,我得到了一个,有什么建议吗?

index.html:12 Uncaught ReferenceError: mobilenet is not defined at index.html:12

<html>
    <head>
        <title>Something else Introduction</title>
        <!----  Import Script---->
        <script src="https://unpkg.com/@tensorflow/tfjs@1.2.8" type="text/javascript" </script>                   
        <script src="https://unpkg.com/@tensorflow-models/mobilenet@2.0.4" type="text/javascript"</script>
    </head>
    <body>
        <img id="img" crossOrigin src = "https://i.imgur.com/e5KD2lt.jpg">
        <h1 id="message">Hello, I'm a simple web page!</h1>
        <script>
            mobilenet.load().then(net => {
            console.log('Model loaded to memory!')
            const theImage = document.getElementById('img')
        net.classify(theImage).then(result=> {
            document.getElementById('message').innerText = `
                Detected: ${result[0].className}
                Probability: ${result[0].Probability}
                `
            })
        })   
        </script>
    </body>
</html>
4

2 回答 2

0

只需将您的<head>标签更改如下:

<script src="https://unpkg.com/@tensorflow/tfjs@1.2.8" type="text/javascript"></script>                   
<script src="https://unpkg.com/@tensorflow-models/mobilenet@2.0.4" type="text/javascript"></script>

补充建议:

<script>在标签末尾使用您的标签,<body>而不是在<head>或只是简单地使用async属性。它将有助于页面加载性能。请在此答案中进一步阅读以获取更长的解释。

我希望这有帮助!

于 2019-12-13T20:04:49.423 回答
0

脚本标签缺少右括号

于 2019-12-13T20:01:42.370 回答