我使用以下代码从mobilenet进行实时推理
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
camera = cv2.VideoCapture(0)
camera.set(3, 1280)
camera.set(4, 1024)
# Loads label file, strips off carriage return
label_lines = [line.rstrip() for line
in tf.gfile.GFile('tf_model/output_labels.txt')]
gpu_options = tf.GPUOptions(allow_growth=True,per_process_gpu_memory_fraction=0.9)
sess_config = tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False,allow_soft_placement = True)
sess_config.gpu_options.per_process_gpu_memory_fraction = 0.9
sess_config.gpu_options.allow_growth=True
def grabVideoFeed():
grabbed, frame = camera.read()
return frame if grabbed else None
def initialSetup():
with tf.device('/gpu:0'):
with tf.gfile.FastGFile('tf_model/output_graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
initialSetup()
with tf.Session(config= sess_config) as sess:
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
while True:
frame = grabVideoFeed()
//do the rest of classification
虽然我曾尝试使用gpu,但仍然没有使用整个gpu。 gpu使用率仅为8%。我该如何解决这个问题呢?