Giter Club home page Giter Club logo

tracycle_ai's Introduction

๐Ÿ”— ํ”„๋ก ํŠธ์—”๋“œ - Tracycle_WebProject_Front

๐Ÿ”— ๋ฐฑ์—”๋“œ - Tracycle_WebProject_Back


๐Ÿ’ป ๊ฐœ๋ฐœํ™˜๊ฒฝ


  • ๊ธฐ๋ณธ ํ™˜๊ฒฝ
    • IDE : VS Code
    • OS : Windows
    • Git
    • Jupyter Notebook
  • ์›น์„œ๋น„์Šค ๊ฐœ๋ฐœํ™˜๊ฒฝ
    • Python
    • Flask
    • Pytorch

๐Ÿš€ Flask API


API : predict()
  • ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๊ฐ’์„ ๋ฐ›๊ณ  yolo5๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ธ์‹ํ•œ ํ›„ ํ•ด๋‹น ์ง€์—ญ๊ตฌ์™€ ์ด๋ฏธ์ง€ ๋ผ๋ฒจ์— ํ•ด๋‹นํ•˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด
userId = request.form.get('userId')
if request.method == 'POST':
    areaId = int(request.form.get('areaId'))
    if "mainFile" not in request.files:
        return redirect(request.url)
    file = request.files["mainFile"]
  • userId, areaId, mainFile์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค
    img_bytes = file.read()
    img = Image.open(io.BytesIO(img_bytes))
    results = model(img, size=640)
    
    results.render()  
    for img in results.imgs:
        img_base64 = Image.fromarray(img)
        img_base64.save("static/"+userId+".jpg", format="JPEG")

    data = results.pandas().xyxy[0].to_json(orient="records")
  • image ๋ฐ›์€ ๊ฒƒ์„ model()์— ๋„ฃ์–ด์„œ yolo๋กœ ๋ถ„์„
  • base64๋กœ ๋ Œ๋”๋งํ•ด์„œ userId + jpg๋กœ ์ €์žฅ
  • ๋ถ„์„์—์„œ ๋‚˜์˜จ label์„ json์œผ๋กœ ์ €์žฅ
    info_list = list()   
    list_data = json.loads(data)
    class_id=set()
    for x in list_data:
        class_id.add(x['class'])
    class_id = list(class_id)

    if not class_id:
        print("Can't find object")
        infos = "Can't find object"

    else:
        for c in class_id:
            categoryId = c
            infos = get_result('tracycle', areaId, categoryId)
            for info in infos:
                info_list.append(info)

return jsonify(info_list)
  • ๋ถ„์„๊ฒฐ๊ณผ ๋ผ๋ฒจ๋ง๋œ ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ์ผ ๊ฒฝ์šฐ ํ•ด๋‹น ๊ฒฐ๊ณผ๋ฅผ ์ „๋ถ€ ๋ฐ›์•„ ๋ฆฌ์ŠคํŠธ์— ์ €์žฅํ›„ json์œผ๋กœ ๋ฆฌํ„ด
Etc. : if name == "main":
  • ์‹œ์ž‘ ์‹œ ํ”Œ๋ผ์Šคํฌ์™€ yolo ๊ตฌ๋™
  • ํ”Œ๋ผ์ŠคํŠธ ์„ค์ • (port, host ์กฐ๊ฑด)
  • yolo ์„ค์ • (torch๋ฅผ ํ†ตํ•ด yolov5 ์ „์ฒด ์ฝ”๋“œ ๋ฐ›์•„์„œ ์ž…๋ ฅ, custom ํŒŒ์ผ๋กœ ์„ค์ • ํ›„ ptํŒŒ์ผ ์œ„์น˜ ์„ค์ • )
    parser = argparse.ArgumentParser(
        description="Flask app exposing yolov5 models")
    parser.add_argument("--port", default=8085, type=int, help="port number")
    args = parser.parse_args()

    model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt').autoshape()  # force_reload = recache latest code
    model.eval()
    # debug=True causes Restarting with stat
    app.run(host="0.0.0.0", port=args.port)

๐Ÿš€ YoloV5


Tracycle(yolov5).ipynb
  • Yolo v5 ๋‹ค์šด๋กœ๋“œ ๋ฐ ์„ค์น˜.
!git clone https://github.com/ultralytics/yolov5
!cd yolov5;pip install -qr requirements.txt
  • ๋Œ€์šฉ๋ž‘ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•œ Google Drive ์ ‘๊ทผ์„ ์œ„ํ•œ ๋งˆ์šดํŠธ
import os, sys 
from google.colab import drive 

drive.mount('/content/gdrive')
  • ์ž๋ฃŒ ์ •์ œํ•˜์—ฌ ๋ผ๋ฒจ๋ง, ๊ฒฐ๋กœ ์„ค์ • ์ž‘์—…์„ ์ •์˜ํ•œ yaml ์ž‘์„ฑ ํŒŒ์ผ ๋ฐ›์•„์˜ค๊ธฐ
!wget -O /content/gdrive/MyDrive/Project_Data/Tracycle_Train.yaml https://raw.github.com/Koartifact/Tracycle_Ai/master/data/util/Tracycle_Train.yaml

  • Train ์ˆ˜ํ–‰ ๋ถ€๋ถ„
  • img 600 : ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ 640์—์„œ ์˜ค๋ฅ˜๊ฐ€ ์žฆ์•„์„œ 600์œผ๋กœ ๋‹ค์šดํ•˜์—ฌ ํ•™์Šต
  • batch 8 : 16 ์„ค์ •์‹œ ๋ณด๋‹ค ์ข‹์€ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์™€ 8๋กœ ์„ค์ •
  • epochs : 130
  • weights : yolov5m. ์ฒ˜์Œ์—๋Š” s๋ชจ๋ธ๋กœ ์‹œ์ž‘ํ•˜์˜€์œผ๋‚˜ ์ข€๋” ์ข‹์€ ์„ฑ๋Šฅ์„ ์œ„ํ•ด m ๋ชจ๋ธ๋กœ ๋ณ€๊ฒฝํ•™์Šต
  • data : yaml ํŒŒ์ผ์œ„์น˜ ์„ค์ •. (๋ผ๋ฒจ๋ง ์ •๋ณด์™€ ํŒŒ์ผ ๊ฒฝ๋กœ)
!cd /content/yolov5; python train.py --img 600 --batch 8 --epochs 130 --data /content/gdrive/MyDrive/Project_Data/Tracycle_Train.yaml --weights yolov5m.pt \
                                     --project=/mydrive/Project_Data --name summary --exist-ok 

Yolo v5 ์•„ํ‚คํ…์ฒ˜
# YOLOv5 ๐Ÿš€ by Ultralytics, GPL-3.0 license

# Parameters
nc: 80  # number of classes
depth_multiple: 0.67  # model depth multiple
width_multiple: 0.75  # layer channel multiple
anchors:
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

# YOLOv5 backbone
backbone:
  # [from, number, module, args]
  [[-1, 1, Focus, [64, 3]],  # 0-P1/2
   [-1, 1, Conv, [128, 3, 2]],  # 1-P2/4
   [-1, 3, C3, [128]],
   [-1, 1, Conv, [256, 3, 2]],  # 3-P3/8
   [-1, 9, C3, [256]],
   [-1, 1, Conv, [512, 3, 2]],  # 5-P4/16
   [-1, 9, C3, [512]],
   [-1, 1, Conv, [1024, 3, 2]],  # 7-P5/32
   [-1, 1, SPP, [1024, [5, 9, 13]]],
   [-1, 3, C3, [1024, False]],  # 9
  ]

# YOLOv5 head
head:
  [[-1, 1, Conv, [512, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 6], 1, Concat, [1]],  # cat backbone P4
   [-1, 3, C3, [512, False]],  # 13

   [-1, 1, Conv, [256, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 4], 1, Concat, [1]],  # cat backbone P3
   [-1, 3, C3, [256, False]],  # 17 (P3/8-small)

   [-1, 1, Conv, [256, 3, 2]],
   [[-1, 14], 1, Concat, [1]],  # cat head P4
   [-1, 3, C3, [512, False]],  # 20 (P4/16-medium)

   [-1, 1, Conv, [512, 3, 2]],
   [[-1, 10], 1, Concat, [1]],  # cat head P5
   [-1, 3, C3, [1024, False]],  # 23 (P5/32-large)

   [[17, 20, 23], 1, Detect, [nc, anchors]],  # Detect(P3, P4, P5)
  ]


๐Ÿ‘ช Contributors


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.