def init_tf_memory(): gpus = tfconf_exp.list_physical_devices('GPU') if gpus: try: for gpu in gpus: tfconf_exp.set_memory_growth(gpu, True) except RuntimeError as e: print(e)
def __init__(self, videoPath: str): # Konstruktor lädt Labels, CNN-Model und YOLO-Modell # Definition Konstanten zur Initialisierung self.VzeIP = VzeImageProcessing(None) self.videoPath = videoPath self.previousTime = cv2.getTickCount() self.frames_count = 0 self.tickFrequency = cv2.getTickFrequency() physical_devices = list_physical_devices('GPU') print("tf number gpu", len(physical_devices)) if len(physical_devices) > 0: set_memory_growth(physical_devices[0], True) # Labels laden try: self.labels = read_csv(LABEL_PATH, sep=";", encoding="mac_latin2") except OSError: print("Labels können nicht geladen werden. Programm wird beendet.") quit() # CNN-Modell laden try: self.model = load_model(CNN_MODEL_PATH) except OSError: print("CNN-Modell kann nicht geladen werden. Programm wird beendet.") quit() # Mean filter image laden try: self.mean = pickle.load(open(YOLO_MEAN_PICKLE, "rb"), encoding='latin1') except OSError: print("Mean-Image kann nicht geladen werden. Programm wird beendet.") quit() # YOLO-Network initialisieren try: self.yolo_network = cv2.dnn.readNetFromDarknet(YOLO_CONFIG_PATH, YOLO_WEIGHTS_PATH) except cv2.error: print("YOLO kann nicht initialisiert werden. Programm wird beendet.") quit() # Layer initialsieren self.layers_names_output = [self.yolo_network.getLayerNames()[i[0] - 1] for i in self.yolo_network.getUnconnectedOutLayers()] # set CUDA as the preferable backend and target if cv2.cuda.getCudaEnabledDeviceCount() > 0: self.yolo_network.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) self.yolo_network.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA) print("FOUND GPU - USING GPU") else: print("NO GPU - USING CPU")
import os import numpy as np import matplotlib.pyplot as plt import tensorflow_datasets as tfds from tensorflow.data import Dataset from tensorflow.keras.optimizers import Adam from tensorflow.data.experimental import AUTOTUNE from tensorflow.keras.callbacks import ModelCheckpoint from tensorflow.config.experimental import set_memory_growth from tensorflow.config import list_physical_devices # Failed to get convolution algorithm physical_devices = list_physical_devices('GPU') set_memory_growth(physical_devices[0], True) # Hyperparameters from cycle.config import ORIG_IMG_SIZE from cycle.config import INPUT_IMG_SIZE from cycle.config import BUFFER_SIZE from cycle.config import BATCH_SIZE from cycle import CycleGAN from cycle.callbacks import GANMonitor from cycle.loss import generator_loss_fn from cycle.loss import discriminator_loss_fn from cycle.generator import get_resnet_generator from cycle.discriminator import get_discriminator from cycle.preprocessing import preprocess_train_image from cycle.preprocessing import preprocess_test_image
default=0.5, help="minimum probability to filter weak detections") ap.add_argument("-r", "--recognizer", required=True, help="path to model trained to recognize faces") ap.add_argument("-b", "--le-recognizer", required=True, help="path to label encoder of recognizer model") args = vars(ap.parse_args()) #only grow tensorflow memory usage as is needed the process(good for low memory GPUs) physical_devices = list_physical_devices('GPU') try: experimental.set_memory_growth(physical_devices[0], True) dlib.DLIB_USE_CUDA = True except: # Invalid device or cannot modify virtual devices once initialized. pass # load our serialized face detector from disk print("[INFO] loading face detector...") protoPath = os.path.sep.join([args["detector"], "deploy.prototxt"]) modelPath = os.path.sep.join( [args["detector"], "res10_300x300_ssd_iter_140000.caffemodel"]) net = cv2.dnn.readNetFromCaffe(protoPath, modelPath) # load the liveness detector model and label encoder from disk print("[INFO] loading liveness detector...") livemodel = load_model(args["livemodel"])
if 20 <= left[0] <= 100: if left[1] <= 130: current_gear = forward_gear print('FORWARD', end='\r') elif 140 <= left[1] <= 340: current_gear = normal_gear print('NORMAL', end='\r') else: current_gear = reverse_gear print('REVERSE', end='\r') else: angle = 0 overlay(frame, rotate(wheel, angle), current_gear) cv2.imshow('Frame', frame) if cv2.waitKey(1) == 27: break # print(f'[INFO] FPS : {1 / (time() - start):.2f}', end='\r') src.stop() cv2.destroyAllWindows() devices = list_physical_devices('GPU') if len(devices) > 0: set_memory_growth(devices[0], True) main()