Skip to content

Commit

Permalink
Jupyter notebook added
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Nomaan Qureshi committed Mar 28, 2020
1 parent 147673e commit c75367e
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 0 deletions.
220 changes: 220 additions & 0 deletions Generate_Occupancy_Grid.ipynb

Large diffs are not rendered by default.

Empty file added __init__.py
Empty file.
Binary file added disparity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inputs/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inputs/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified models/MaskRCNN/output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added models/PSMNet/.nfs00000000023707d70000000a
Binary file not shown.
1 change: 1 addition & 0 deletions models/PSMNet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added models/PSMNet/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
101 changes: 101 additions & 0 deletions models/PSMNet/generate_disparity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from __future__ import print_function
import argparse
import os
import random
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim as optim
import torch.utils.data
from torch.autograd import Variable
import torch.nn.functional as F
import skimage
import skimage.io
import skimage.transform
import numpy as np
import time
import math
from utils import preprocess
from models import *
import cv2

model = stackhourglass(192)

model = nn.DataParallel(model)
model.cuda()

#loadmodel = './trained/pretrained_model_KITTI2015.tar'
loadmodel = './models/PSMNet/trained/pretrained_model_KITTI2015.tar'
print('load PSMNet')
state_dict = torch.load(loadmodel)
model.load_state_dict(state_dict['state_dict'])

print('Number of model parameters: {}'.format(sum([p.data.nelement() for p in model.parameters()])))

def test(imgL,imgR):
model.eval()

if torch.cuda.is_available():
imgL = torch.FloatTensor(imgL).cuda()
imgR = torch.FloatTensor(imgR).cuda()

imgL, imgR= Variable(imgL), Variable(imgR)

with torch.no_grad():
disp = model(imgL,imgR)

disp = torch.squeeze(disp)
pred_disp = disp.data.cpu().numpy()

return pred_disp


def generate_disparity(leftimg, rightimg, isgray):
processed = preprocess.get_transform(augment=False)
if isgray:
imgL_o = cv2.cvtColor(cv2.imread(leftimg,0), cv2.COLOR_GRAY2RGB)
imgR_o = cv2.cvtColor(cv2.imread(rightimg,0), cv2.COLOR_GRAY2RGB)
else:
imgL_o = (skimage.io.imread(leftimg).astype('float32'))
imgR_o = (skimage.io.imread(rightimg).astype('float32'))

imgL = processed(imgL_o).numpy()
imgR = processed(imgR_o).numpy()
imgL = np.reshape(imgL,[1,3,imgL.shape[1],imgL.shape[2]])
imgR = np.reshape(imgR,[1,3,imgR.shape[1],imgR.shape[2]])

# pad to width and hight to 16 times
if imgL.shape[2] % 16 != 0:
times = imgL.shape[2]//16
top_pad = (times+1)*16 -imgL.shape[2]
else:
top_pad = 0
if imgL.shape[3] % 16 != 0:
times = imgL.shape[3]//16
left_pad = (times+1)*16-imgL.shape[3]
else:
left_pad = 0
imgL = np.lib.pad(imgL,((0,0),(0,0),(top_pad,0),(0,left_pad)),mode='constant',constant_values=0)
imgR = np.lib.pad(imgR,((0,0),(0,0),(top_pad,0),(0,left_pad)),mode='constant',constant_values=0)

start_time = time.time()
pred_disp = test(imgL,imgR)
print('time = %.2f' %(time.time() - start_time))
if top_pad !=0 or left_pad != 0:
img = pred_disp[top_pad:,:-left_pad]
else:
img = pred_disp
img = (img*256).astype('uint16')
skimage.io.imsave('./outputs/disparity/disparity.png',img)

#img = np.concatenate((imgL_o, imgR_o),axis=1)
#img = cv2.line(img, (0, 240), (1504, 240), (0, 0, 255), 2)
#img = cv2.line(img, (0, 210), (1504, 210), (0, 0, 255), 2)
#img = cv2.line(img, (0, 270), (1504, 270), (0, 0, 255), 2)
#skimage.io.imsave('test.png',img)





Binary file modified models/PSMNet/models/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified models/PSMNet/models/__pycache__/basic.cpython-36.pyc
Binary file not shown.
Binary file modified models/PSMNet/models/__pycache__/stackhourglass.cpython-36.pyc
Binary file not shown.
Binary file modified models/PSMNet/utils/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Empty file added models/__init__.py
Empty file.
Binary file added models/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions models/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from PSMNet.generate_disparity import generate_disparity

generate_disparity('./PSMnet/left.png', './PSMnet/right.png', False)
Binary file added outputs/instance_segmentation/output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import cv2
import sys
sys.path.insert(1, 'models/PSMNet')
from generate_disparity import generate_disparity

left = cv2.imread('left.png')
right = cv2.imread('right.png')
generate_disparity(left, right, False)

0 comments on commit c75367e

Please sign in to comment.