Created
April 15, 2020 18:03
-
-
Save Quasimondo/3b1c206356484d3f3e7e8e4a7bfe5e30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import time | |
import torch | |
import torch.nn.functional as F | |
kernel = np.ones((41, 41) ).astype(np.float32) | |
cv_input = (np.random.random(size=(500,500))>0).astype(np.float32) | |
kernel_tensor = torch.Tensor(kernel).cuda().unsqueeze(0).unsqueeze(0) | |
torch_input = torch.Tensor(cv_input).cuda().unsqueeze(0).unsqueeze(0) | |
padding = (int(41/2), int(41/2)) | |
t = time.time() | |
for i in range(100): | |
for _ in range(10): | |
cv_input = cv2.morphologyEx(cv_input, cv2.MORPH_CLOSE, kernel ) | |
print("cv",time.time()-t) | |
t = time.time() | |
for i in range(100): | |
for _ in range(10): | |
torch_input = 1-torch.clamp(F.conv2d(1-torch.clamp(F.conv2d(torch_input, kernel_tensor, padding=padding), 0, 1), kernel_tensor, padding=padding), 0, 1) | |
print("cuda",time.time()-t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment