Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cpu #3

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: support cpu
  • Loading branch information
yihong0618 committed Sep 22, 2021
commit ab30fcf6e864628baf03c8df21f99344b65278cd
20 changes: 10 additions & 10 deletions model_torch.py
Original file line number Diff line number Diff line change
@@ -238,11 +238,13 @@ def loadImages(folder):
if __name__ == "__main__":
model = res_skip()
model.load_state_dict(torch.load('erika.pth'))

model.cuda()
is_cuda = torch.cuda.is_available()
if is_cuda:
model.cuda()
else:
model.cpu()
model.eval()


filelists = loadImages(sys.argv[1])

with torch.no_grad():
@@ -255,8 +257,11 @@ def loadImages(folder):
# manually construct a batch. You can change it based on your usecases.
patch = np.ones((1,1,rows,cols),dtype="float32")
patch[0,0,0:src.shape[0],0:src.shape[1]] = src

tensor = torch.from_numpy(patch).cuda()

if is_cuda:
tensor = torch.from_numpy(patch).cuda()
else:
tensor = torch.from_numpy(patch).cpu()
y = model(tensor)
print(imname, torch.max(y), torch.min(y))

@@ -266,8 +271,3 @@ def loadImages(folder):

head, tail = os.path.split(imname)
cv2.imwrite(sys.argv[2]+"/"+tail.replace(".jpg",".png"),yc[0:src.shape[0],0:src.shape[1]])





2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
torch==1.9.1
opencv-python