이 문서는 Google Cloud Translation API를 사용해 자동 번역되었습니다.
어떤 문서는 원문을 읽는게 나을 수도 있습니다.
이 게시물에서는 TensorFlow.js 및 Node.js를 사용하여 실시간 개체 감지를 수행하는 방법을 알아봅니다.
TensorFlow.js는 자바스크립트 기계 학습을 위한 오픈 소스 라이브러리입니다. 이를 통해 브라우저 또는 Node.js 환경에서 기계 학습 모델을 훈련하고 실행할 수 있습니다.
Node.js는 브라우저 외부에서 JavaScript 코드를 실행할 수 있는 JavaScript 런타임 환경입니다.
TensorFlow.js 및 Node.js를 사용하여 다음을 통해 실시간 객체 감지를 수행할 수 있습니다.
이미지에서 개체를 감지하는 기계 학습 모델을 교육하는 것부터 시작하겠습니다. 이를 위해 MobileNet 모델을 사용합니다. MobileNet은 대규모 이미지 데이터 세트에 대해 훈련된 사전 훈련된 모델입니다.
MobileNet을 사용하여 다음을 통해 물체 감지를 수행할 수 있습니다.
코드에서 이 작업을 수행하는 방법을 살펴보겠습니다.
// Load the MobileNet model.
const model = await mobilenet.load();
// Classify the image.
const predictions = await model.classify(image);
// Get the model's predictions.
console.log(predictions);
모델을 교육하고 나면 Node.js 서버에 배포할 수 있습니다. 이를 통해 들어오는 이미지를 처리하고 실시간으로 개체를 감지할 수 있습니다.
이렇게 하려면 다음이 필요합니다.
코드에서 이 작업을 수행하는 방법을 살펴보겠습니다.
// Install the TensorFlow.js library.
npm install @tensorflow/tfjs
// Install the Node.js library.
npm install node
// Create a Node.js server.
const tf = require('@tensorflow/tfjs');
const express = require('express');
const app = express();
//Deploy the model to the server.
app.use(express.static(__dirname + '/model'));
// Process incoming images and detect objects in real-time.
app.post('/api/detect', async (req, res) => {
// Classify the image.
const predictions = await model.classify(req.body.image);
// Send the predictions to the client.
res.json(predictions);
});
// Start the server.
app.listen(3000, () => console.log('Server is running on port 3000'));
서버가 가동되고 실행되면 서버를 사용하여 들어오는 이미지를 처리하고 객체를 실시간으로 감지할 수 있습니다.
이렇게 하려면 다음이 필요합니다.
코드에서 이 작업을 수행하는 방법을 살펴보겠습니다.
// Send an image to the server.
const image = 'some-image.jpg';
fetch('/api/detect', {
method: 'POST',
body: JSON.stringify({ image }),
})
.then(res => res.json())
.then(predictions => {
// Use the predictions to detect objects in the image.
console.log(predictions);
});
이 게시물에서는 TensorFlow.js 및 Node.js를 사용하여 실시간 객체 감지를 수행하는 방법을 배웠습니다.