Skip to content

Adds requirements file #13

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
34 changes: 23 additions & 11 deletions demo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import argparse
from fire import Fire
import numpy as np
from PIL import Image
from scipy.misc import imresize
import torch
import torch.nn.parallel

from models import modules, net, resnet, densenet, senet
import numpy as np
import loaddata_demo as loaddata
import pdb

import matplotlib.image
import matplotlib.pyplot as plt
Expand All @@ -29,23 +30,34 @@ def define_model(is_resnet, is_densenet, is_senet):
return model


def main():
def main(image_path):
model = define_model(is_resnet=False, is_densenet=False, is_senet=True)
model = torch.nn.DataParallel(model).cuda()
model.load_state_dict(torch.load('./pretrained_model/model_senet'))
model = torch.nn.DataParallel(model)
if torch.cuda.is_available():
model = model.cuda()
model.load_state_dict(torch.load(
f='./pretrained_model/model_senet',
map_location=None if torch.cuda.is_available() else 'cpu'))
model.eval()

nyu2_loader = loaddata.readNyu2('data/demo/img_nyu2.png')
nyu2_loader = loaddata.readNyu2(image_path)

test(nyu2_loader, model)


def test(nyu2_loader, model):
for i, image in enumerate(nyu2_loader):
image = torch.autograd.Variable(image, volatile=True).cuda()
image = torch.autograd.Variable(image, volatile=True)
if torch.cuda.is_available():
image = image.cuda()
out = model(image)

matplotlib.image.imsave('data/demo/out.png', out.view(out.size(2),out.size(3)).data.cpu().numpy())

out = out.view(out.size(2), out.size(3)).data.cpu().numpy()
input_shape = image.data.cpu().numpy().shape[2:4]
out = imresize(arr=out, size=input_shape)
Image.fromarray(out.astype(np.uint8)).save('data/demo/out.png')

# matplotlib.image.imsave('data/demo/out.png', out)

if __name__ == '__main__':
main()
Fire(main)
2 changes: 0 additions & 2 deletions loaddata.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pandas as pd
import numpy as np
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms, utils
from PIL import Image
import random
from nyu_transform import *


Expand Down
3 changes: 0 additions & 3 deletions loaddata_demo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import pandas as pd
import numpy as np
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms, utils
from PIL import Image
import random
from demo_transform import *


Expand Down
9 changes: 1 addition & 8 deletions models/modules.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
from collections import OrderedDict
import math
import torch
import torch.nn.functional as F
import torch.nn as nn
from torch.utils import model_zoo
import copy
import numpy as np
import senet
import resnet
import densenet


class _UpProjection(nn.Sequential):

Expand Down
12 changes: 1 addition & 11 deletions models/net.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
from collections import OrderedDict
import math
import torch
import torch.nn.functional as F
import torch.nn as nn
from torch.utils import model_zoo
import copy
import numpy as np
import modules
from torchvision import utils
from models import modules

import senet
import resnet
import densenet

class model(nn.Module):
def __init__(self, Encoder, num_features, block_channel):
Expand Down
2 changes: 0 additions & 2 deletions nyu_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import random
import scipy.ndimage as ndimage

import pdb


def _is_pil_image(img):
if accimage is not None:
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numpy
matplotlib
torch
torchvision
2 changes: 0 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import argparse
import torch
import torch.nn as nn
import torch.nn.parallel

from models import modules, net, resnet, densenet, senet
Expand Down
2 changes: 0 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import torch.backends.cudnn as cudnn
import torch.optim
import loaddata
import util
import numpy as np
import sobel
from models import modules, net, resnet, densenet, senet

Expand Down