def run_pspnet_3C_modelPath(filename, caminhoIn, modelPath, protoPath, setLabel=True): caminhoFile = os.path.join(caminhoIn, filename + ".jpg") nameDivided = filename.split(".") # load image, switch to BGR, subtract mean, and make dims C x H x W for Caffe im = Image.open(caminhoFile) imSize = im.size im = im.resize((473, 473)) in_ = np.array(im, dtype=np.float32) in_ = in_[:, :, ::-1] in_ -= np.array((104.00698793, 116.66876762, 122.67891434)) in_ = in_.transpose((2, 0, 1)) print caminhoFile net = caffe.Net(protoPath, modelPath, caffe.TEST) # shape for input (data blob is N x C x H x W), set data print "img entreda: " #print in_.shape print caminhoFile #descomentar para 3 canais #print "img depth: " #print depthIn.shape net.blobs['color'].reshape(1, *in_.shape) net.blobs['color'].data[...] = in_ label = cv2.imread( '/home/conteinerFiles/skin-images/masks/{}.png'.format(filename), 0) #label = label.resize((473,473)) label = cv2.resize(label, (473, 473)) label = getBinaryImage(label) if (setLabel): sumLabel = 0 label = label[np.newaxis, ...] net.blobs['label'].reshape(1, *label.shape) net.blobs['label'].data[...] = label return (net, label)
def LoadNet(protoPath, modelPath): net = caffe.Net(protoPath, modelPath, caffe.TEST) return net
try: import setproctitle setproctitle.setproctitle(os.path.basename(os.getcwd())) except: pass weights = '../ilsvrc-nets/vgg16-fcn.caffemodel' #uncommment for Speed #base_net = caffe.Net('/home/hmelo/fcnd/ilsvrc-nets/vgg16fcn.prototxt', '/home/hmelo/fcnd/ilsvrc-nets/vgg16fcn.prototxt.caffemodel', # caffe.TEST) #base_net = caffe.Net('/home/conteinerFiles/pspnet/pspnetpython/ilsvrc-nets/vgg16fcn.prototxt', '/home/conteinerFiles/pspnet/pspnetpython/ilsvrc-nets/vgg16fcn.prototxt.caffemodel', # caffe.TEST) base_net = caffe.Net( '/home/conteinerFiles/pspnet/PSPNet/evaluation/prototxt/pspnet101_VOC2012_473.prototxt', '/home/conteinerFiles/pspnet/PSPNet/evaluation/model/pspnet101_VOC2012.caffemodel', caffe.TEST) # init #caffe.set_device(int(sys.argv[1])) caffe.set_device(0) caffe.set_mode_gpu() #caffe.set_mode_cpu() #solver = caffe.SGDSolver('/home/hmelo/fcnd/nyud-fcn32s-color-d/solver.prototxt') if args.path_solver: print "Solver path: " + args.path_solver solver = caffe.SGDSolver(args.path_solver) else: solver = caffe.SGDSolver(