Giter VIP home page Giter VIP logo

socar_project's Introduction

Socar_Project : Vehicle Damage Detection using Video Data


This project contains content for vehicle damage detection using video.

Author : Jinwoo Jang

Open In Colab

Description Open In Notion


This project deals with the problem of object detection, which uses video data to determine whether a vehicle is damaged or not.
especially, in this project, YOLOv5 is used as the object detection model.

Here is some examples for frame images


[evaluation images for object detection model]

Run detect.py


  1. replace detect.py in YOLOv5 to provided detect.py
  2. run detect.py using provided best.py
!python detect.py --weight yolov5_trained_pt/train/socar_hackathon_yolov5m4/weights/best.pt --source "{video_sample}" 

Detection logic


Using the queue and the confirm rate, if the same class in the queue has more than the confirm rate, it is decided that the class has an actual error.

## in detect.py

from collections import deque

## for Detection Queue
MAX_QUEUE_LEN = 5
MAX_CONFIRM_CLASS = 3
DAMAGE_CLASS_DICT = {0:'Crack', 1:'Dent', 2:'Scratch'}
##

## for video class detection
detection_queue = deque()
detected_class = []
##

for path, im, im0s, vid_cap, s in dataset:
	    t1 = time_sync()
      im = torch.from_numpy(im).to(device)
      im = im.half() if model.fp16 else im.float()  # uint8 to fp16/32
      im /= 255  # 0 - 255 to 0.0 - 1.0
      if len(im.shape) == 3:
          im = im[None]  # expand for batch dim
      t2 = time_sync()
      dt[0] += t2 - t1

      # Inference
      visualize = increment_path(save_dir / Path(path).stem, mkdir=True) if visualize else False
      pred = model(im, augment=augment, visualize=visualize)
      t3 = time_sync()
      dt[1] += t3 - t2

      # NMS
      pred = non_max_suppression(pred, conf_thres, iou_thres, classes, agnostic_nms, max_det=max_det)
      dt[2] += time_sync() - t3

      # Second-stage classifier (optional)
      # pred = utils.general.apply_classifier(pred, classifier_model, im, im0s)

      # Process predictions
      for i, det in enumerate(pred):  # per image
          ## for class clarification
          if det[:, -1].nelement() == 0:
              dmg_class = [-1]
          else:
              dmg_class = det[:, -1].unique().tolist()
      
          detection_queue.append(dmg_class)
          
          dmg_class = [0,0,0] # 0 : crack class / 1 : dent class / 2 : scratch class
          
          if len(detection_queue) == MAX_QUEUE_LEN:
              #print(detection_queue)
              for queue in detection_queue:
                  for q in queue:
                      if int(q) != -1:
                          dmg_class[int(q)] += 1
                      else:
                          continue
              
              for c, dmg in enumerate(dmg_class):
                  if dmg >= MAX_CONFIRM_CLASS:
                      detected_class.append(c)
                  
              detection_queue.popleft()
          ##

					##...
					##...
					##...

print("Detected Class : {}".format( [DAMAGE_CLASS_DICT[x] for x in set(detected_class)]))


'''
Results

if damaged parts is detected 
print Detected Class : ['Dent'] or Detected Class : ['Dent', 'Scratch'] ...
else
print Detected Class : []
'''

socar_project's People

Contributors

jinwoo1126 avatar

Watchers

 avatar

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.