이 글은 생활코딩 님의 Tensorflow (JavaScript) 수업을 들으면서 정리한 글이다.
https://opentutorials.org/course/4628
<!DOCTYPE html>
<html>
<body>
<!-- Load TensorFlow.js Library. This is required to use MobileNet. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.1"> </script>
<!-- Load the MobileNet model. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@1.0.0"> </script>
<!-- Replace this with your image. Make sure CORS settings allow reading the image! -->
<img id="img" src="dog.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>
브라우저
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script>
NPM에서 설치
npm install @tensorflow/tfjs
또는
yarn add @tensorflow/tfjs
install 후 다음과 같은 방법으로 사용 가능
var tf = require('@tensorflow/tfjs');