<jupyter_start><jupyter_text>YOLO-Net<jupyter_code># imports
import cv2
import numpy as np
from tqdm import tqdm_notebook as tqdm 
import requests
import math
import matplotlib.pyplot as plt
import os

# local imports
import plai.workspace.init # source setup.bash
from plai.yolo import demo
from plai.yolo.model.yolo_model import YOLO
# Force CPU @todo Use GPU
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"   # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"] = ""
# Download trained Yolo Net
ws_root = plai.workspace.init.get_ws_path()
   
if not os.path.exists( os.path.join(ws_root, 'res', 'trained', 'yolo.h5') ) or \
    os.path.getsize( os.path.join(ws_root, 'res', 'trained', 'yolo.h5') ) < 248714728:
    
    # Get yolonet from : https://my.hidrive.com/lnk/MVgiq50v
    url = "https://downloads.codingcoursestv.eu/037%20-%20neuronale%20netze/yolo.h5"

    r = requests.get(url, stream=True)

    # Total size in bytes.
    total_size = int(r.headers.get('content-length', 0)); 
    block_size = 1024
    with open( os.path.join(ws_root, 'res', 'trained', 'yolo.h5'), 'wb') as f:
        for data in tqdm(r.iter_content(block_size), total=math.ceil(total_size//block_size), unit='KB', unit_divisor=1024, unit_scale=True):
            f.write(data)
else:
    print('File already existent')
# Load YOLO net
yolo = YOLO(0.6, 0.5, os.path.join(ws_root, 'res', 'trained', 'yolo.h5') )
# COCO: Common Objects in Contact (http://cocodataset.org/)
#   Popular ML dataset
#   https://www.tensorflow.org/datasets/catalog/coco

file = os.path.join(ws_root, 'common', 'plai', 'plai', 'yolo', 'data', 'coco_classes.txt')
all_classes = demo.get_classes(file)
# Read image
img = cv2.imread("../res/bild3.jpg")
#img = cv2.imread("../res/yolo.jpg")
img = cv2.resize(img, ( int(img.shape[1] / 2), int( img.shape[0] / 2) ) )
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

plt.imshow(img)
plt.show()
# Detect classes on image
img = demo.detect_image(img, yolo, all_classes)
# Visualize detected classes
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

plt.figure(figsize=(12, 12), dpi=80, facecolor='w', edgecolor='k')

plt.axis('off')
plt.imshow(img)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15806159420289856, 'fraction_numerical': 0.026721014492753624, 'mean_word_length': 4.467821782178218, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '427751', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 906, 'n_tokens_neox': 869, 'n_words': 183, 'path': 'common/tutorials/src/DL_11_YOLO_Net.ipynb', 'repo_name': 'maximilianharr/plai', 'size': '2208'}