Skip to content

Instantly share code, notes, and snippets.

View pythonlessons's full-sized avatar
🏠
Working from home

Rokas Liuberskis pythonlessons

🏠
Working from home
View GitHub Profile
def residual_block(input_layer, input_channel, filter_num1, filter_num2, activate_type='leaky'):
short_cut = input_layer
conv = convolutional(input_layer, filters_shape=(1, 1, input_channel, filter_num1), activate_type=activate_type)
conv = convolutional(conv , filters_shape=(3, 3, filter_num1, filter_num2), activate_type=activate_type)
residual_output = short_cut + conv
return residual_output
def cspdarknet53(input_data):
input_data = convolutional(input_data, (3, 3, 3, 32), activate_type="mish")
@pythonlessons
pythonlessons / Convert_to_pb.py
Created August 19, 2020 17:15
Convert_to_pb
import tensorflow as tf
from yolov3.yolov4 import Create_Yolo
from yolov3.utils import load_yolo_weights
from yolov3.configs import *
if YOLO_TYPE == "yolov4":
Darknet_weights = YOLO_V4_TINY_WEIGHTS if TRAIN_YOLO_TINY else YOLO_V4_WEIGHTS
if YOLO_TYPE == "yolov3":
Darknet_weights = YOLO_V3_TINY_WEIGHTS if TRAIN_YOLO_TINY else YOLO_V3_WEIGHTS
@pythonlessons
pythonlessons / Convert_to_TRT.py
Last active August 20, 2020 08:31
Convert_to_TRT
import tensorflow as tf
import numpy as np
physical_devices = tf.config.experimental.list_physical_devices('GPU')
if len(physical_devices) > 0:
tf.config.experimental.set_memory_growth(physical_devices[0], True)
from yolov3.configs import *
from tensorflow.python.compiler.tensorrt import trt_convert as trt
def calibration_input():
for i in range(100):
@pythonlessons
pythonlessons / multiprocessing_pipe_numpy.py
Last active September 16, 2020 05:42
multiprocessing_pipe_numpy
from multiprocessing import Process, Pipe
import time
import numpy as np
def send_to_pipe(q, mylist):
# function to put elements into Pipe
for num in mylist:
q.send(np.random.random((416, 416, 3)))
def pick_from_pipe(q, mylist):
@pythonlessons
pythonlessons / multiprocessing_pipe_simple.py
Created September 15, 2020 13:56
multiprocessing_pipe_simple.py
from multiprocessing import Process, Pipe
import time
def send_to_pipe(q, mylist):
# function to put elements into Pipe
for num in mylist:
q.send(num)
def pick_from_pipe(q, mylist):
# function to print pipe elements
@pythonlessons
pythonlessons / multiprocessing_queue_numpy.py
Created September 15, 2020 13:57
multiprocessing_queue_numpy.py
from multiprocessing import Process, Queue
import time
import numpy as np
def send_to_queue(q, mylist):
# function to put elements into Queue
for num in mylist:
q.put(np.random.random((416, 416, 3)))
def pick_from_queue(q, mylist):
@pythonlessons
pythonlessons / multiprocessing_queue_simple.py
Created September 15, 2020 13:57
multiprocessing_queue_simple.py
from multiprocessing import Process, Queue
import time
def send_to_queue(q, mylist):
# function to put elements into Queue
for num in mylist:
q.put(num)
def pick_from_queue(q, mylist):
# function to print queue elements
@pythonlessons
pythonlessons / Multiprocessing_video.py
Created September 17, 2020 12:18
Multiprocessing_video
def Predict_bbox_mp(Frames_data, Predicted_data, Processing_times):
gpus = tf.config.experimental.list_physical_devices('GPU')
if len(gpus) > 0:
try: tf.config.experimental.set_memory_growth(gpus[0], True)
except RuntimeError: print("RuntimeError in tf.config.experimental.list_physical_devices('GPU')")
Yolo = Load_Yolo_model()
times = []
while True:
if Frames_data.qsize()>0:
image_data = Frames_data.get()
@pythonlessons
pythonlessons / utils.py
Created September 18, 2020 13:03
multiprocessing_test
from multiprocessing import Process, Queue, Pipe
import cv2
import time
import random
import colorsys
import numpy as np
import tensorflow as tf
from yolov3.configs import *
from yolov3.yolov4 import *
from tensorflow.python.saved_model import tag_constants
@pythonlessons
pythonlessons / Collect_training_data.py
Last active September 29, 2020 08:29
Collect_training_data
offset = 30
sct = mss.mss()
yolo = Load_Yolo_model()
while True:
img = np.array(sct.grab({"top": 87-offset, "left": 1920, "width": 1280, "height": 720, "mon": -1}))
img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)
image, bboxes = detect_enemy(yolo, np.copy(img), input_size=YOLO_INPUT_SIZE, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0))
if len(bboxes) > 0:
CreateXMLfile("XML_Detections", str(int(time.time())), img, bboxes, read_class_names(TRAIN_CLASSES))
print("got it")