SHARE
TWEET

output_graph

a guest Jun 19th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from mvnc import mvncapi as mvnc
  2.  
  3. import numpy as np
  4. import cv2
  5.  
  6. def pre_process_img(img,PREPROCESS_DIMS):
  7.     img = cv2.resize(img, PREPROCESS_DIMS)
  8.     img = img - 127.5
  9.     img = img / 127.5
  10.     return img.astype(np.float32)
  11.  
  12. #path to the graph file
  13. GRAPH_FILEPATH1 = 'graphs/graph2'
  14.  
  15. device_list = mvnc.enumerate_devices()
  16. device = mvnc.Device(device_list[0])
  17. device.open()
  18.  
  19. with open(GRAPH_FILEPATH1, mode='rb') as f: graph_buffer1 = f.read()
  20. graph1 = mvnc.Graph('graph1')
  21.  
  22. input_fifo, output_fifo = graph1.allocate_with_fifos(device, graph_buffer1)
  23.  
  24. cap = cv2.VideoCapture(0)
  25. ret, frame = cap.read()
  26.  
  27. PREPROCESS_DIMS = (300, 300)
  28.  
  29. img = pre_process_img(frame,PREPROCESS_DIMS)
  30.  
  31. graph1.queue_inference_with_fifo_elem(input_fifo, output_fifo, img, None)
  32. output, user_obj = output_fifo.read_elem()
  33.  
  34. print("shape is: {}".format(np.shape(output)))
  35.  
  36. input_fifo.destroy()
  37. output_fifo.destroy()
  38. graph1.destroy()
  39. device.close()
  40. device.destroy()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top