there is my code
i firstly tried the cuda visible devices but it didnt worked then i tried :
with tf.device(gpus1.name):
not working either for me
when GPU's is free : nvidia-smi image 1
when i started the code my GPU's memory :nvidia-smi image 2
i deleted some parts of code cause its not relevant what i ask this code didnt pops error when i started but i couldnt split the code between two GPU's can you pls help me?
"""import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]="0,1"""
import pyzed.sl as sl
import cv2
from pixellib.instance import instance_segmentation
import time
import threading
import numpy as np
from cgi import print_arguments
import tensorflow as tf
tf.debugging.set_log_device_placement(True)
gpus1= tf.config.experimental.list_physical_devices('GPU')
config = tf.config.experimental.set_memory_growth(gpus1[1], True)
config = tf.config.experimental.set_memory_growth(gpus1[0], True)
gpus = tf.config.list_logical_devices('GPU')
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
import serial
import time
from sklearn.datasets import make_sparse_spd_matrix
while 1 :
with tf.device(gpus[1].name):
res = segmentation_model.segmentFrame(frame, show_bboxes=False)
frame = res[1]
print("flag1")
cv2.imshow("mask",frame)
cv2.waitKey(1)
with tf.device(gpus[0].name):
image =frame
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_expanded = np.expand_dims(image_rgb, axis=0)
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image_expanded})
#------------------------------------------------
try:
conf_threshold = 0.5
nms_threshold = 0.45
image_shape = image.shape[:2]
filtered_scores = [scores[0][i] for i in np.where(scores[0] > conf_threshold)]
filtered_boxes = [boxes[0][i] for i in np.where(scores[0] > conf_threshold)]
filtered_classes = [classes[0][i] for i in np.where(scores[0] > conf_threshold)]
if len(filtered_scores[0]) != 0:
# NMS thresholding
indices, count = apply_non_max_suppression(filtered_boxes[0], filtered_scores[0], nms_threshold, 200)
selected_indices = indices[:count]
## Getting the final boxes
final_boxes = filtered_boxes[0][selected_indices]
final_scores = filtered_scores[0][selected_indices]
final_classes = filtered_classes[0][selected_indices]
final_boxes = [denormalize_box(box, image_shape) for box in final_boxes]
# final_boxes = [x_min, y_min, x_max, y_max]
#-------------------------------------------------
# Draw the results of the detection (aka 'visulaize the results')
vis_util.visualize_boxes_and_labels_on_image_array(
image,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8,
min_score_thresh=0.9)
#-------------------------------------
class_and_box = []
for i in range(len(final_boxes)):
if ( final_scores[i]>0.90):
case = {final_classes[i] : final_boxes[i]}
class_and_box.append(case)
#print(class_and_box)
def kutu_orta_nokta(liste):
xmin, ymin, xmax, ymax = liste
x, y = ((xmin+xmax)/2, (ymin+ymax)/2)
center = int(x), int(y)
cv2.circle(image, center, radius=10, color=(255, 0, 255), thickness=-1)
return center
sag_liste= []
orta_liste = []
sol_liste= []
cv2.imshow('Object detector', image)
cv2.waitKey(1)
print('[Info] Time Taken: {} | FPS: {}'.format(time.time() - timer, 1 / (time.time() - timer)),
end='\r')