Skip to content

Instantly share code, notes, and snippets.

@Yuvnish017
Created June 24, 2021 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuvnish017/29b931d597ee5303943f81dc339d3bc4 to your computer and use it in GitHub Desktop.
Save Yuvnish017/29b931d597ee5303943f81dc339d3bc4 to your computer and use it in GitHub Desktop.
model = cv2.dnn.readNetFromTorch('udnie.t7')
image = cv2.imread('yuvnish malhotra photo.jpg')
(h, w) = image.shape[:2]
image = cv2.resize(image, (600, h))
(h, w, c) = image.shape
print(h, w, c)
blob = cv2.dnn.blobFromImage(image, 1.0, (w, h), (103.939, 116.779, 123.680), swapRB=False, crop=False)
model.setInput(blob)
output = model.forward()
output = output.reshape((3, output.shape[2], output.shape[3]))
output[0] += 103.939
output[1] += 116.779
output[2] += 123.680
output /= 255.0
output = output.transpose(1, 2, 0)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
figure = plt.figure(figsize=(10, 10))
plt.imshow(image)
plt.axis('off')
figure2 = plt.figure(figsize=(10, 10))
plt.imshow(output)
plt.axis('off')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment