프로그래밍/Developer Student Clubs

[YOLO 웹으로 구현한 프로젝트 조사]

지누; 2020. 2. 2. 13:46

[파이썬에서 darkflow 사용하기]

🔗Github : https://github.com/thtrieu/darkflow

 

thtrieu/darkflow

Translate darknet to tensorflow. Load trained weights, retrain/fine-tune using tensorflow, export constant graph def to mobile devices - thtrieu/darkflow

github.com

from darkflow.net.build import TFNet
import cv2
options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1}
tfnet = TFNet(options)
imgcv = cv2.imread("./sample_img/sample_dog.jpg")
result = tfnet.return_predict(imgcv)
print(result)

❗️Please note that return_predict(img) must take an numpy.ndarray.

return_predict(img)전에 이미지가 미리 로드되어 있어야 함. 파일 경로를 넘기는 것은 작동하지 않음.

return_predict(img) 의 결과는 리스트 형태의 딕셔너리로 반환.

 

[django with yolo v3]

🔗Github: https://github.com/tranleanh/Yolov3-Django-Streaming

 

tranleanh/Yolov3-Django-Streaming

This project is to stream an object detection module (Yolo v3) with 2 cameras (2 channels) on a web browser using Django. - tranleanh/Yolov3-Django-Streaming

github.com

🔗영상링크 : https://www.youtube.com/watch?v=SDnpNd7xRbE

 

[React로 구현한 yolo with tensorflow.js]

🔗예시 : https://z364noozrm.codesandbox.io/

🔗구현코드링크: https://codesandbox.io/s/z364noozrm

 

TensorFlow.js Real-Time Object Detection - CodeSandbox

TensorFlow.js Real-Time Object Detection by bourdakos1 using @tensorflow-models/coco-ssd, @tensorflow/tfjs, react, react-dom, react-magic-dropzone, react-scripts

codesandbox.io

// 패키지 JSON
{
  "name": "tensorflowjs-real-time-object-detection",
  "version": "1.0.0",
  "description": "",
  "keywords": [],
  "main": "src/index.js",
  "dependencies": {
    "@tensorflow-models/coco-ssd": "0.1.1",
    "@tensorflow/tfjs": "0.14.0",
    "react": "16.5.2",
    "react-dom": "16.5.2",
    "react-magic-dropzone": "1.0.1",
    "react-scripts": "2.0.3"
  },
  "devDependencies": {},
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "browserslist": [">0.2%", "not dead", "not ie <= 11", "not op_mini all"]
}

 

[구글 codelab 에 있는 tensorflow.js 예시]

  • yolo 사용은 안하고 knn 알고리즘 사용한 프로젝트인데 만약에 tensorflow.js 쓰게 되면 처음 뼈대 잡기 좋을 것 같다.

🔗Google Codelab : https://codelabs.developers.google.com/codelabs/tensorflowjs-teachablemachine-codelab/#0

 

TensorFlow.js Transfer Learning Image Classifier

In this codelab, you will learn how to build a simple "teachable machine", a custom image classifier that you will train on the fly in the browser using TensorFlow.js, a powerful and flexible machine learning library for Javascript. You will first load and

codelabs.developers.google.com

  • 설명: 웹캠 키고 학습시키고자 하는 동작을 취하고 각각 Add A, Add B, Add C 버튼을 누른 후 특정 동작을 취하면 prediction 값과 probability 값이 나온다.

const classifier = knnClassifier.create();
const webcamElement = document.getElementById('webcam');
let net;

async function app() {
  console.log('Loading mobilenet..');

  // Load the model.
  net = await mobilenet.load();
  console.log('Successfully loaded model');

  // Create an object from Tensorflow.js data API which could capture image
  // from the web camera as Tensor.
  const webcam = await tf.data.webcam(webcamElement);

  // Reads an image from the webcam and associates it with a specific class
  // index.
  const addExample = async classId => {
    // Capture an image from the web camera.
    const img = await webcam.capture();

    // Get the intermediate activation of MobileNet 'conv_preds' and pass that
    // to the KNN classifier.
    const activation = net.infer(img, 'conv_preds');

    // Pass the intermediate activation to the classifier.
    classifier.addExample(activation, classId);

    // Dispose the tensor to release the memory.
    img.dispose();
  };

  // When clicking a button, add an example for that class.
  document.getElementById('class-a').addEventListener('click', () => addExample(0));
  document.getElementById('class-b').addEventListener('click', () => addExample(1));
  document.getElementById('class-c').addEventListener('click', () => addExample(2));

  while (true) {
    if (classifier.getNumClasses() > 0) {
      const img = await webcam.capture();

      // Get the activation from mobilenet from the webcam.
      const activation = net.infer(img, 'conv_preds');
      // Get the most likely class and confidences from the classifier module.
      const result = await classifier.predictClass(activation);

      const classes = ['A', 'B', 'C'];
      document.getElementById('console').innerText = `
        prediction: ${classes[result.label]}\n
        probability: ${result.confidences[result.label]}
      `;

      // Dispose the tensor to release the memory.
      img.dispose();
    }

    await tf.nextFrame();
  }
}

app();

 

[구글이 제공하는 teachable machine]

https://teachablemachine.withgoogle.com/?fbclid=IwAR2y1juwJUpJ6rcHbcy4RkjAP1paKrFagfCyHR3399fhobUOuTAQGMe7nsk

 

Teachable Machine

Train a computer to recognize your own images, sounds, & poses. A fast, easy way to create machine learning models for your sites, apps, and more – no expertise or coding required.

teachablemachine.withgoogle.com