def main(): # location of depth module, config and parameters model_name = 'depthnormals_nyud_alexnet' #model_name = 'depthnormals_nyud_vgg' # module_fn = 'models/iccv15/%s.py' % model_name # config_fn = 'models/iccv15/%s.conf' % model_name # params_dir = 'weights/iccv15/%s' % model_name module_fn = 'models/iccv15/depthnormals_nyud_alexnet.py' #% model_name config_fn = 'models/iccv15/depthnormals_nyud_alexnet.conf' #% model_name params_dir = 'weights/iccv15/depthnormals_nyud_alexnet' #% model_name # load depth network machine = net.create_machine(module_fn, config_fn, params_dir) # demo image rgb = Image.open('thyroid.jpg') rgb = rgb.resize((320, 240), Image.BICUBIC) #rergb = Image.fromarray(rgb) rgb.save("thyroid.jpg") # build depth inference function and run rgb_imgs = np.asarray(rgb).reshape((1, 240, 320, 3)) (pred_depths, pred_normals) = machine.infer_depth_and_normals(rgb_imgs) # save prediction depth_img_np = depth_montage(pred_depths) depth_img = Image.fromarray((255 * depth_img_np).astype(np.uint8)) depth_img.save('demo_depth_prediction_thyroid.png') normals_img_np = normals_montage(pred_normals) normals_img = Image.fromarray((255 * normals_img_np).astype(np.uint8)) normals_img.save('demo_normals_prediction_thyroid.png')
def main(): # location of depth module, config and parameters model_name = 'depthnormals_nyud_alexnet' #model_name = 'depthnormals_nyud_vgg' # module_fn = 'models/iccv15/%s.py' % model_name # config_fn = 'models/iccv15/%s.conf' % model_name # params_dir = 'weights/iccv15/%s' % model_name module_fn = 'models/iccv15/depthnormals_nyud_alexnet.py' #% model_name config_fn = 'models/iccv15/depthnormals_nyud_alexnet.conf' #% model_name params_dir = 'weights/iccv15/depthnormals_nyud_alexnet' #% model_name # load depth network machine = net.create_machine(module_fn, config_fn, params_dir) # demo image rgb = Image.open('thyroid.jpg') rgb = rgb.resize((320, 240), Image.BICUBIC) #rergb = Image.fromarray(rgb) rgb.save("thyroid.jpg") # build depth inference function and run rgb_imgs = np.asarray(rgb).reshape((1, 240, 320, 3)) (pred_depths, pred_normals) = machine.infer_depth_and_normals(rgb_imgs) # save prediction depth_img_np = depth_montage(pred_depths) depth_img = Image.fromarray((255*depth_img_np).astype(np.uint8)) depth_img.save('demo_depth_prediction_thyroid.png') normals_img_np = normals_montage(pred_normals) normals_img = Image.fromarray((255*normals_img_np).astype(np.uint8)) normals_img.save('demo_normals_prediction_thyroid.png')
def main(): # location of depth module, config and parameters module_fn = 'models/depth_kitti.py' config_fn = 'models/depth_kitti.conf' params_dir = 'weights/depth_kitti' # load depth network machine = net.create_machine(module_fn, config_fn, params_dir) # demo image rgb = Image.open('demo_kitti_rgb.jpg') rgb = rgb.resize((612, 184), Image.BICUBIC) # build depth inference function and run rgb_imgs = np.asarray(rgb).reshape((1, 184, 612, 3)) pred_depths = machine.infer_depth(rgb_imgs) # save prediction (m, M) = (pred_depths.min(), pred_depths.max()) depth_img_np = (pred_depths[0] - m) / (M - m) depth_img = Image.fromarray((255 * depth_img_np).astype(np.uint8)) depth_img.save('demo_kitti_depth_prediction.png') import matplotlib.pyplot as plt plt.ion() import ipdb ipdb.set_trace() pass
def machine2model(): module_fn = 'models/iccv15/depthnormals_nyud_alexnet.py' #% model_name config_fn = 'models/iccv15/depthnormals_nyud_alexnet.conf' #% model_name params_dir = 'weights/iccv15/depthnormals_nyud_alexnet' #% model_name trainMachine = net.create_machine(module_fn, config_fn, params_dir) #model = trainMachine.define_machine() print trainMachine return trainMachine
def load_depth_nn( model_name="depthnormals_nyud_vgg", nn_path="/afs/csail.mit.edu/u/y/yuvval/externals/dnl-depthnormals/" ): # model_name = 'depthnormals_nyud_alexnet' # an alternative model_name # add path of the neural network sys.path.append(nn_path) from utils import depth_montage, normals_montage import net depth_nn = dict() # location of depth module, config and parameters depth_nn["model_name"] = model_name depth_nn["module_fn"] = "%smodels/iccv15/%s.py" % (nn_path, model_name) depth_nn["config_fn"] = "%smodels/iccv15/%s.conf" % (nn_path, model_name) depth_nn["params_dir"] = "%sweights/iccv15/%s" % (nn_path, model_name) # load depth network depth_nn["machine"] = net.create_machine(depth_nn["module_fn"], depth_nn["config_fn"], depth_nn["params_dir"]) return depth_nn
def load_depth_nn( model_name='depthnormals_nyud_vgg', nn_path='/afs/csail.mit.edu/u/y/yuvval/externals/dnl-depthnormals/'): #model_name = 'depthnormals_nyud_alexnet' # an alternative model_name # add path of the neural network sys.path.append(nn_path) from utils import depth_montage, normals_montage import net depth_nn = dict() # location of depth module, config and parameters depth_nn['model_name'] = model_name depth_nn['module_fn'] = '%smodels/iccv15/%s.py' % (nn_path, model_name) depth_nn['config_fn'] = '%smodels/iccv15/%s.conf' % (nn_path, model_name) depth_nn['params_dir'] = '%sweights/iccv15/%s' % (nn_path, model_name) # load depth network depth_nn['machine'] = net.create_machine(depth_nn['module_fn'], depth_nn['config_fn'], depth_nn['params_dir']) return depth_nn
def main(): # location of depth module, config and parameters module_fn = 'models/depth.py' config_fn = 'models/depth.conf' #网络结构 params_dir = 'weights/depth' #网络相关参数 # load depth network machine = net.create_machine(module_fn, config_fn, params_dir) # demo image rgb = Image.open('demo_nyud_rgb.jpg') rgb = rgb.resize((320, 240), Image.BICUBIC) # build depth inference function and run rgb_imgs = np.asarray(rgb).reshape((1, 240, 320, 3)) pred_depths = machine.infer_depth(rgb_imgs) # save prediction (m, M) = (pred_depths.min(), pred_depths.max()) depth_img_np = (pred_depths[0] - m) / (M - m) depth_img = Image.fromarray((255 * depth_img_np).astype(np.uint8)) depth_img.save('demo_nyud_depth_prediction.png')
def main(): # location of depth module, config and parameters module_fn = 'models/depth.py' config_fn = 'models/depth.conf'#网络结构 params_dir = 'weights/depth'#网络相关参数 # load depth network machine = net.create_machine(module_fn, config_fn, params_dir) # demo image rgb = Image.open('demo_nyud_rgb.jpg') rgb = rgb.resize((320, 240), Image.BICUBIC) # build depth inference function and run rgb_imgs = np.asarray(rgb).reshape((1, 240, 320, 3)) pred_depths = machine.infer_depth(rgb_imgs) # save prediction (m, M) = (pred_depths.min(), pred_depths.max()) depth_img_np = (pred_depths[0] - m) / (M - m) depth_img = Image.fromarray((255*depth_img_np).astype(np.uint8)) depth_img.save('demo_nyud_depth_prediction.png')
import os import sys import numpy as np from PIL import Image import net def predictDepth(filelist, pwd): image_w = 416 image_h = 218 # location of depth module, config and parameters module_fn = pwd + '/eigen/models/depth_kitti.py' config_fn = pwd + '/eigen/models/depth_kitti.conf' params_dir = pwd + '/eigen/weights/depth_kitti' # load depth network machine = net.create_machine(module_fn, config_fn, params_dir) rgb_imgs = [] # demo image for filename in filelist: rgb = Image.open(filename) rgb = rgb.resize((image_w, image_h), Image.BICUBIC) rgb_imgs.append(rgb) # build depth inference function and run rgb_imgs = np.asarray(rgb_imgs).reshape((len(filelist), image_h, image_w, 3)) pred_depths = machine.infer_depth(rgb_imgs) # save prediction # (m, M) = (pred_depths.min(), pred_depths.max()) # depth_img_np = (pred_depths[0] - m) / (M - m) np.save(pwd + "/eigen/output/depth.npy", pred_depths) return pred_depths