TensorFlow.js 前端检测用户上传了什么图片并打标签

C 2023-11-15 4067

直接搬官方示例:

<!DOCTYPE>
<html>

<head>
  <link rel="icon" href="data:,">

</head>

<body>
  <!-- Load TensorFlow.js. This is required to use MobileNet. -->
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"> </script>
  <!-- Load the MobileNet model. -->
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet"> </script>

  <!-- Replace this with your image. Make sure CORS settings allow reading the image! -->
  <img id="img" src="cat.jpg"></img>

  <!-- Place your code in the script tag below. You can also use an external .js file -->
  <script>
    // Notice there is no 'import' statement. 'mobilenet' and 'tf' is
    // available on the index-page because of the script tag above.

    const img = document.getElementById('img');

    // Load the model.
    mobilenet.load().then(model => {
      // Classify the image.
      model.classify(img).then(predictions => {
        console.log('Predictions: ');
        console.log(predictions);
      });
    });
  </script>

</body>

</html>

image.webp

最新回复 (4)
  • C 2023-11-15
    2

    精度一般,柴犬会被识别成柯基。

    image.webp

  • zeg922 2023-11-15
    3
    C 精度一般,柴犬会被识别成柯基。

    是狗就行了呗,要求别那么高。

  • v6666 2023-11-15
    4

    这个模型权重加载时间会很长

  • C 2023-11-15
    5
    v6666 这个模型权重加载时间会很长

    没事,边上传边加载,就是给用户个标签建议

    • 屌丝论坛
      6