<jupyter_start><jupyter_text>Real Time Detections<jupyter_code># colab is not available to steam 
cap = cv2.VideoCapture(0)
while cap.isOpened():
    ret, frame = cap.read()
    
    # Make detections 
    results = model(frame)
    
    cv2.imshow('YOLO', np.squeeze(results.render()))
    
    if cv2.waitKey(10) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()<jupyter_output><empty_output><jupyter_text>Train from scratch<jupyter_code>import uuid   # Unique identifier
import os
import time
IMAGES_PATH = os.path.join('data', 'images') #/data/images
labels = ['awake', 'drowsy']
number_imgs = 20
cap = cv2.VideoCapture(0)
# Loop through labels
for label in labels:
    print('Collecting images for {}'.format(label))
    time.sleep(5)
    
    # Loop through image range
    for img_num in range(number_imgs):
        print('Collecting images for {}, image number {}'.format(label, img_num))
        
        # Webcam feed
        ret, frame = cap.read()
        
        # Naming out image path
        imgname = os.path.join(IMAGES_PATH, label+'.'+str(uuid.uuid1())+'.jpg')
        
        # Writes out image to file 
        cv2.imwrite(imgname, frame)
        
        # Render to the screen
        cv2.imshow('Image Collection', frame)
        
        # 2 second delay between captures
        time.sleep(2)
        
        if cv2.waitKey(10) & 0xFF == ord('q'):
            break
cap.release()
cv2.destroyAllWindows()
print(os.path.join(IMAGES_PATH, labels[0]+'.'+str(uuid.uuid1())+'.jpg'))
for label in labels:
    print('Collecting images for {}'.format(label))
    for img_num in range(number_imgs):
        print('Collecting images for {}, image number {}'.format(label, img_num))
        imgname = os.path.join(IMAGES_PATH, label+'.'+str(uuid.uuid1())+'.jpg')
        print(imgname)

!git clone https://github.com/tzutalin/labelImg
!pip install pyqt5 lxml --upgrade
%cd labelImg
!pyrcc5 -o libs/resources.py resources.qrc
%cd ..
%cd yolov5
!python train.py --img 320 --batch 16 --epochs 500 --data dataset.yml --weights yolov5s.pt --workers 2<jupyter_output><empty_output><jupyter_text><jupyter_code># Load Custom Model
model = torch.hub.load('ultralytics/yolov5', 'custom', path='/content/drive/MyDrive/YOLOv5_Practice/yolov5/runs/train/exp7/weights/best.pt', force_reload=True)

img_awake = "/content/drive/MyDrive/YOLOv5_Practice/data/images/awake.7f6b1803-3c34-11ec-b24f-94e6f7a1c25e.jpg"
img_drowsy = "/content/drive/MyDrive/YOLOv5_Practice/data/images/drowsy.92ad39fd-3c34-11ec-a5a3-94e6f7a1c25e.jpg"

results_awake = model(img_awake)
results_drowsy = model(img_drowsy)
results_awake.print()
results_drowsy.print()
%matplotlib inline 
plt.imshow(np.squeeze(results_awake.render()))
plt.show()
%matplotlib inline 
plt.imshow(np.squeeze(results_drowsy.render()))
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13934713934713935, 'fraction_numerical': 0.029133029133029134, 'mean_word_length': 3.6341463414634148, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '649411', 'license': 'MIT', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1038, 'n_words': 197, 'path': 'YOLO_Drowsiness_Detection/YOLO_Drowsiness_Detection_For_Training_And_Testing.ipynb', 'repo_name': 'Hacker-Davinci/YOLO_Skilled_Projects', 'size': '2849'}