def vis_pairs(prms, isSave=False, svIdx=None, svPath=None):
	imName1, imName2, euls, trans = read_pairs(prms)
	N = len(imName1)
	seed      = 3
	randState = np.random.RandomState(seed)
	perm = randState.permutation(N)
	fig = plt.figure()
	plt.ion()
	imName1 = [imName1[i] for i in perm]
	imName2 = [imName2[i] for i in perm]
	euls    = [euls[i] for i in perm]
	trans   = [trans[i] for i in perm]
	titleStr = 'Trans: ' + '%.3f ' * 3 + 'Rot: ' + '%.3f ' * 3
	count   = 0
	numSave = 0
	for (im1,im2,eu,tr) in zip(imName1, imName2, euls, trans):
		titleName = titleStr % (tuple(tr) + eu)
		im1 = scm.imread(im1)
		im2 = scm.imread(im2)
		print count
		if isSave:
			if count in svIdx:
				imN1 = svPath % (count,1)
				imN2 = svPath % (count,2)
				scm.imsave(imN1,im1)
				scm.imsave(imN2,im2)
				numSave += 1
				if numSave==len(svIdx):
					return 
		else:
			vu.plot_pairs(im1, im2, fig, titleStr=titleName)
			cmd = raw_input()	
			if cmd == 'exit':
				return
		count += 1
def vis_pairs(prms, isSave=False, svIdx=None, svPath=None):
    imName1, imName2, euls, trans = read_pairs(prms)
    N = len(imName1)
    seed = 3
    randState = np.random.RandomState(seed)
    perm = randState.permutation(N)
    fig = plt.figure()
    plt.ion()
    imName1 = [imName1[i] for i in perm]
    imName2 = [imName2[i] for i in perm]
    euls = [euls[i] for i in perm]
    trans = [trans[i] for i in perm]
    titleStr = 'Trans: ' + '%.3f ' * 3 + 'Rot: ' + '%.3f ' * 3
    count = 0
    numSave = 0
    for (im1, im2, eu, tr) in zip(imName1, imName2, euls, trans):
        titleName = titleStr % (tuple(tr) + eu)
        im1 = scm.imread(im1)
        im2 = scm.imread(im2)
        print count
        if isSave:
            if count in svIdx:
                imN1 = svPath % (count, 1)
                imN2 = svPath % (count, 2)
                scm.imsave(imN1, im1)
                scm.imsave(imN2, im2)
                numSave += 1
                if numSave == len(svIdx):
                    return
        else:
            vu.plot_pairs(im1, im2, fig, titleStr=titleName)
            cmd = raw_input()
            if cmd == 'exit':
                return
        count += 1
예제 #3
0
def test_group_rots(isPlot=True, debugMode=True):
    import vis_utils as vu
    import matplotlib.pyplot as plt
    fig = plt.figure()
    defFile = osp.join(MODULE_PATH, 'test/test_group_rots.prototxt')
    net = caffe.Net(defFile, caffe.TEST)
    while True:
        data = net.forward(blobs=['pair_data', 'pose_label'])
        im, pk = data['pair_data'], data['pose_label']
        im += 128
        im = im.astype(np.uint8)
        if isPlot:
            for b in range(10):
                if debugMode:
                    rots = tuple(pk[b].squeeze())[0:6]
                else:
                    rots = tuple(pk[b].squeeze())[0:3]
                rots = [(r * 180.) / np.pi for r in rots]
                figTitle = 'yaw: %f,  pitch: %f, roll: %f \n yaw: %f, pitch:%f, roll: %f'\
                         % (rots[0], rots[1], rots[2], rots[3], rots[4], rots[5])
                ax = vu.plot_pairs(im[b, 0:3],
                                   im[b, 3:6],
                                   isBlobFormat=True,
                                   chSwap=(2, 1, 0),
                                   fig=fig,
                                   figTitle=figTitle)
                plt.draw()
                plt.show()
                ip = raw_input()
                if ip == 'q':
                    return
def test_group_rots(isPlot=True, debugMode=True):
	import vis_utils as vu
	import matplotlib.pyplot as plt
	fig     = plt.figure()
	defFile = osp.join(MODULE_PATH, 'test/test_group_rots.prototxt')
	net     = caffe.Net(defFile, caffe.TEST)
	while True:
		data   = net.forward(blobs=['pair_data', 'pose_label'])
		im, pk = data['pair_data'], data['pose_label']
		im     += 128
		im     = im.astype(np.uint8)
		if isPlot:
			for b in range(10):
				if debugMode:
					rots = tuple(pk[b].squeeze())[0:6]
				else:
					rots = tuple(pk[b].squeeze())[0:3]
				rots = [(r * 180.)/np.pi for r in rots]
				figTitle = 'yaw: %f,  pitch: %f, roll: %f \n yaw: %f, pitch:%f, roll: %f'\
             % (rots[0], rots[1], rots[2], rots[3], rots[4], rots[5])
				ax = vu.plot_pairs(im[b,0:3], im[b,3:6], isBlobFormat=True,
             chSwap=(2,1,0), fig=fig, figTitle=figTitle)
				plt.draw()
				plt.show()
				ip = raw_input()
				if ip == 'q':
					return	
예제 #5
0
def test_poke_layer_regression(isPlot=True):
    import vis_utils as vu
    import matplotlib.pyplot as plt
    fig = plt.figure()
    defFile = 'test/poke_layer.prototxt'
    net = caffe.Net(defFile, caffe.TEST)
    while True:
        data = net.forward(blobs=['im', 'poke'])
        im, pk = data['im'], data['poke']
        if isPlot:
            for b in range(10):
                ax = vu.plot_pairs(im[b, 0:3],
                                   im[b, 3:6],
                                   isBlobFormat=True,
                                   chSwap=(2, 1, 0),
                                   fig=fig)
                ax[0].plot(int(pk[b][0]),
                           int(pk[b][1]),
                           markersize=10,
                           marker='o')
                plt.draw()
                plt.show()
                ip = raw_input()
                if ip == 'q':
                    return
예제 #6
0
def vis_liberty_ptch():
    libPrms = rlp.get_prms()
    wFile = libPrms.paths.wFile
    wDat = mpio.GenericWindowReader(wFile)
    rootDir = libPrms.paths.jpgDir
    plt.ion()
    fig = plt.figure()
    while True:
        imNames, lbs = wDat.read_next()
        imNames = [osp.join(rootDir, n.split()[0]) for n in imNames]
        figTitle = '%d' % lbs[0][0]
        im1 = plt.imread(imNames[0])
        im2 = plt.imread(imNames[1])
        vu.plot_pairs(im1, im2, fig=fig, figTitle=figTitle)
        inp = raw_input('Press a key to continue')
        if inp == 'q':
            return
예제 #7
0
def vis_results_pose(prms, cPrms, modelIter):
    #Initialize the network
    exp = se.setup_experiment(prms, cPrms)
    modelFile = exp.get_snapshot_name(numIter=modelIter)
    defFile = exp.expFile_.def_
    net = caffe.Net(defFile, modelFile, caffe.TEST)
    bSz = exp.get_layer_property('window_data', 'batch_size', phase='TEST')
    crpSz = int(
        exp.get_layer_property('window_data', 'crop_size', phase='TEST'))
    muFile = exp.get_layer_property('window_data', 'mean_file')[1:-1]
    mn = mp.read_mean(muFile).transpose(1, 2, 0)
    st = int((227 - 101) / 2.0)
    print mn.shape
    mn = mn[st:st + 101, st:st + 101, :]
    mn = mn[:, :, [2, 1, 0]]
    plt.ion()
    count = 0
    numBatches = 5
    fig = plt.figure()
    for nb in range(numBatches):
        #Generate results on test set
        data = net.forward(['data', 'data_p', 'pose_fc', 'pose_label'])
        for b in range(int(bSz)):
            predLbl = data['pose_fc'][b].squeeze()
            predEuler = ru.quat2euler(predLbl)
            gtLbl = data['pose_label'][b].squeeze()
            gtEuler = ru.quat2euler(gtLbl)
            tStr = 'GT- roll: %.2f, yaw: %.2f, pitch: %.2f\n'\
                + 'PD- roll: %.2f, yaw: %.2f, pitch: %.2f'
            #pdb.set_trace()
            tStr = tStr % (gtEuler + predEuler)
            im1 = data['data'][b].transpose(1, 2, 0).squeeze()
            im2 = data['data_p'][b].transpose(1, 2, 0).squeeze()
            im1 = np.maximum(0, np.minimum(255, im1[:, :, [2, 1, 0]] + mn))
            im2 = np.maximum(0, np.minimum(255, im2[:, :, [2, 1, 0]] + mn))
            #pdb.set_trace()
            vu.plot_pairs(im1, im2, fig, figTitle=tStr)
            count += 1
            imName = exp.paths.testImVis % count
            plt.savefig(imName)
예제 #8
0
def vis_window_file(prms, setName='test', isSave=False,
										labelType='pose_ptch', isEuler=True,
										wFileName=None):
	if prms == 'pascal3d':
		rootDir = '/data0/pulkitag/data_sets/pascal_3d-my-copy/PASCAL3D+_release1.1/Images/'
		wFile   = 'pose-files/euler_test_pascal3d.txt'
		labelType = 'pose'
		pascalFlag = True
	else:
		pascalFlag = False
		rootDir = se.get_windowfile_rootdir(prms)
		if wFileName is None:
			wFile = prms.paths.windowFile[setName]
		else:
			wFile = wFileName 
	wDat    = mpio.GenericWindowReader(wFile)
	runFlag = True
	if labelType == 'pose_ptch':
		if isEuler:
			lbStr   = 'yaw: %.2f, pitch: %.2f, isRot: %d'\
								+ '\n patchMatch: %.2f'
		else:
			lbStr   = 'roll: %.2f, yaw: %.2f, pitch: %.2f, isRot: %d'\
								+ '\n patchMatch: %.2f'
	elif labelType == 'pose':
		if pascalFlag:
			lbStr   = 'yaw: %.2f, pitch: %.2f'
		else:
			lbStr   = 'roll: %.2f, yaw: %.2f, pitch: %.2f, isRot: %d'
	elif labelType == 'ptch':
		lbStr   = 'IsMatch: %d'
	elif labelType == 'nrml':
		lbStr = 'nx: %.4f, ny: %.4f'
	else:
		raise Exception('%s not recognized' % labelType)	
	
	plt.ion()
	fig = plt.figure()
	count = 0
	maxCount = 100				
	while runFlag:
		imNames, lbs = wDat.read_next()
		coords   = [n.strip().split()[4:8] for n in imNames]
		print coords
		coords   = [int(c) for c in coords[0]]
		imNames  = [osp.join(rootDir, n.split()[0]) for n in imNames]
		#pdb.set_trace()
		if 'pose' in labelType:
			if isEuler:
				yaw, pitch = lbs[0][0:2]
				yaw        = (yaw * 180./6.)
				pitch      = (pitch * 180./6.)
				if not pascalFlag:
					isRot          = lbs[0][2]
			else:
				q1, q2, q3, q4 = lbs[0][0:4]
				roll, yaw, pitch = ru.quat2euler([q1, q2, q3, q4])
				roll  = 180 * (roll/np.pi)
				yaw   = 180 * (yaw/np.pi)
				pitch = 180 * (pitch/np.pi)
				isRot          = lbs[0][4]

		if labelType == 'pose_ptch':
			if isEuler:
				pMatch = lbs[0][3]
				figTitle = lbStr % (yaw, pitch, isRot, pMatch)
			else:
				pMatch = lbs[0][5]
				figTitle = lbStr % (roll, yaw, pitch, isRot, pMatch)
		elif labelType == 'pose':
			if pascalFlag:
				figTitle = lbStr % (yaw, pitch)
			else:
				figTitle = lbStr % (roll, yaw, pitch, isRot)
		elif labelType == 'ptch':
			figTitle = lbStr % lbs[0][0]
		elif labelType == 'nrml':
			figTitle = lbStr % (lbs[0][0], lbs[0][1])

		print (figTitle, count)
		im1      = plt.imread(imNames[0])
		if len(imNames) == 2:
			im2      = plt.imread(imNames[1])
			vu.plot_pairs(im1, im2, fig=fig, figTitle=figTitle)
		else:
			x1, y1, x2, y2 = coords
			plt.imshow(im1[y1:y2, x1:x2,:])
			plt.title(figTitle)	
		if isSave:
			outName = osp.join('debug-data', '%05d.jpg' % count)
			plt.savefig(outName)
		else:	
			inp = raw_input('Press a key to continue')
			if inp=='q':
				return
		count = count + 1
		if count >= maxCount:
			runFlag = False