Beispiel #1
0
import numpy as np
import pandas as pd

data_test = pd.read_csv('test3.csv')

data_test = np.array(data_test.iloc[:, 1:])
print(data_test)
data_test = data_test.reshape(data_test.shape[0], 1, 28, 28)
data_test = data_test.astype('float32')
data_test /= 255

argmax = lambda res: np.argmax(res.reshape(10))

cases = []
labels = []

cases.append(data_test)  # Append the image to list of images to process
labels.append(0)  # Append the correct answer to compare later

# Create a runtime engine from plan file using TensorRT Lite API
engine_single = Engine(PLAN="test_engine.engine",
                       postprocessors={"dense_2/Softmax": argmax})

results = []

for image in cases:
    result = engine_single.infer(image)  # Single function for inference
    results.append(result)

print(results)
Beispiel #2
0
engine_single = Engine(PLAN="dncnn.engine")
GT_data_dir = 'data/Test/Set12'
GT_file_list = sorted(glob.glob(GT_data_dir + '/*.png'))


print("TensorRT Testing...")
for i in range(len(GT_file_list)):
    GT_img = cv2.imread(GT_file_list[i], 0) / 255
    GT_img_reshape = GT_img.reshape(1, GT_img.shape[0], GT_img.shape[1], 1)
    noise = np.random.normal(0, 25 / 255.0, GT_img_reshape.shape)
    test_img = GT_img_reshape + noise
    print(test_img.shape)
    test_img_transpose = np.transpose(test_img, [0, 3, 1, 2])

    start_time2 = time.time()
    result = engine_single.infer(test_img_transpose)  # 这是个list类型的输出
    print("process one image use: %4.4f s" % (time.time() - start_time2))


    result = np.array(result).squeeze(axis=0)
    result = np.transpose(result, [0, 2, 3, 1])

    MSE_DNCNN = np.float32(np.mean(np.square(result - GT_img_reshape)))
    PSNR_DNCNN = np.multiply(10.0, np.log(1.0 * 1.0 / MSE_DNCNN) / np.log(10.0))
    print('Picture[%d]   MSE:[%.8f]   PSNR:[%.4f] ---------DNCNN_trt' % ((i + 1), MSE_DNCNN, PSNR_DNCNN))

    result = result.squeeze()
    image_path = os.path.join(os.getcwd(), 'result_dncnn')
    image_path1 = os.path.join(image_path, "test_trt_image_" + str(i) + ".png")
    imsave(result, image_path1)
Beispiel #3
0
# Serialize TensorRT engine to a file for when you are ready to deploy your model.
trt.utils.write_engine_to_file(engine_name, 
                               engine.serialize())
							   
# Create a runtime engine from plan file using TensorRT Lite API 
engine_single = Engine(PLAN=engine_name,
                       postprocessors={output_node_name:analyze})


#Image processing
args = iCap.parse_args()
cap = iCap.open_cam_onboard(args.image_width, args.image_height)
if not cap.isOpened():

	sys.exit('Failed to open camera!')


for i in range(0, 1500):
	abc, vid = cap.read()
	#vid = load_and_preprocess_images()
	if vid.shape[0] != input_width:
				if vid.shape[1] != input_height:
					im = cv2.resize(im, (input_width, input_height))
			im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
			im = (im.astype('float') / 255.0)
			im = np.array(im)
			im = np.expand_dims(im, axis=0)
	#results = []#for image in images_trt:
	prediction = engine_single.infer(im) # Single function for inference
	print(prediction)