if not grabbed:
		break

	#frame = cv2.resize(frame, (256,256), interpolation = cv2.INTER_LINEAR)
	frame = imutils.resize(frame, width= 256)

	#constructing a blob from our image
	blob = cv2.dnn.blobFromImage(cv2.resize(
	    frame, (256, 256)), 1/255.0, (256, 256), 0, swapRB=True, crop=False)

	#Open the model and run forward pass with the given blob
	with open(model_file, "rb") as f:
	    model_bytes = f.read()
	ot = OnnxTransformer(model_bytes)
	start = time.time()
	pred = ot.fit_transform(blob)
	end = time.time()

	# Infer the total number of classes, height and width
	(numClasses, height, width) = pred.shape[1:4]

	# Argmax is utilized to find the class label with largest probability for every pixel in the image
	classMap = np.argmax(pred[0], axis=0)

	# classes are mapped to their respective colours
	mask = COLORS[classMap]

	# resizing the mask and class map to match its dimensions with the input image
	mask = cv2.resize(
	    mask, (frame.shape[1], frame.shape[0]), interpolation=cv2.INTER_NEAREST)
	classMap = cv2.resize(
Esempio n. 2
0
#####################################
# Let's create the OnnxTransformer
# which we apply on that particular image.

with open(model_file, "rb") as f:
    model_bytes = f.read()

ot = OnnxTransformer(model_bytes)

img2 = img.resize((224, 224))
X = np.asarray(img2).transpose((2, 0, 1))
X = X[np.newaxis, :, :, :] / 255.0
print(X.shape, X.min(), X.max())

pred = ot.fit_transform(X)[0, :]
print(pred.shape)

#############################
# And the best classes are...

results = nlargest(10, range(pred.shape[0]), pred.take)
print(results)

data = [{
    "index": i,
    "label": labels.get(str(i), ('?', '?'))[1],
    'score': pred[i]
} for i in results]
df = pandas.DataFrame(data)
print(df)