os.environ['CUDA_VISIBLE_DEVICES'] = '0' import time import cv2 import json import glob import numpy as np import matplotlib.pyplot as plt import random import keras import tensorflow as tf from tensorflow.python.keras import backend as K from model_wrapper.utils import voc, sub_plot, Tick, new_session from deeplab.warpper import Deeplab_Wrapper sess = new_session() xception = Deeplab_Wrapper(sess, 'xception') mobilenet = Deeplab_Wrapper(sess, 'mobilenetv2') from mask_rcnn.warpper import predict, plot cap = cv2.VideoCapture('tmp/videos/9_Very_Close_Takeoffs_Landings.mp4') fourcc = cv2.VideoWriter_fourcc(*'XVID') font = cv2.FONT_HERSHEY_SIMPLEX out = cv2.VideoWriter('tmp/deeplab_cmp.avi', fourcc, 30.0, (640 * 2, 360 * 2)) counter, filter1, filter2, filter3 = 0, 0, 0, 0 while (cap.isOpened()): with Tick(str(counter)): ret, frame_bgr = cap.read() frame_bgr = cv2.resize(frame_bgr, (0, 0), fx=0.5, fy=0.5) frame_rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
cv2.waitKey(1) if self.output_compressed: msg = CompressedImage() msg.header = ros_data.header msg.format = "jpeg" msg.data = np.array(cv2.imencode('.jpg', detections)[1]).tostring() self.pub.publish(msg) else: msg = Image() msg.header = ros_data.header msg.data = detections.tostring() self.pub.publish(msg) def shutdownFunction(signalnum, frame): print('Exit') rospy.signal_shutdown(0) signal.signal(signal.SIGINT, shutdownFunction) signal.signal(signal.SIGTERM, shutdownFunction) if __name__ == '__main__': assert sys.argv[1] in ['mobilenetv2', 'xception'], sys.argv[1] wrapper = Deeplab_Wrapper(new_session(), sys.argv[1]) input_topic = sys.argv[2] output_topic = sys.argv[3] node = Deeplab_Node(wrapper, input_topic, output_topic) rospy.spin()
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' os.environ['CUDA_VISIBLE_DEVICES'] = '0' import cv2 import time import glob import numpy as np import matplotlib.pyplot as plt from model_wrapper.utils import Tick,new_session from model_wrapper.classification import Model_Wrapper,top_n wrapper = Model_Wrapper(new_session(),'mobilenet_v2_1.0') wrapper.print_support_models() for fn in glob.glob('data/ImageNet/*'): with Tick('interference'): prediction = wrapper.predict(fn) print('\n'+top_n(prediction,n=5))