def newFace(alpha_mat, beta_mat, count):
	shape_mat = numpy.array(coef2object(alpha_mat, shapeMU, shapePC, shapeEV, segMM, segMB, 1))
	tex_mat = numpy.array(coef2object(alpha_mat, texMU, texPC, texEV, segMM, segMB, 1))
	tex_mat=tex_mat.swapaxes(0, 1)
	tex_mat.shape=(53490, 3)
	print(shape_mat.shape, tex_mat.shape)

	vertices = blenderMesh(shape_mat)
	colors = blenderColors(tex_mat, tl)
	
	# show('Face0')
	modifyMesh(vertices, colors)
	write(outputPath, 0, 0, 'Fence', count)
	if occluder == 'Curtain':
		Curtain.curtainParameterization(outputPath, faceNumber, faceAngle, occlusionLevel, 'None', 0, 1)
	if occluder == 'Blinds':
		Blinds.blindsParameterization(outputPath, faceNumber, faceAngle, occlusionLevel, 'None', 0, 1)
	if occluder == 'Fence':
		Fence.fenceParameterization(outputPath, faceNumber, faceAngle, occlusionLevel, 'None', 0, 1)

args = sys.argv[sys.argv.index('--') + 1:]
faceNumber = int(args[0])

outputBase = '/om/user/janner/mit/urop/picture/centos/dDiff-dOccl/results/trainingSet/'

shapeMU, shapePC, shapeEV, texMU, texPC, texEV, segMM, segMB, tl = loadModel()
for faceNumber in range(faceNumber, faceNumber + 1):
	outputPath = outputBase + 'Face' + str(faceNumber) + '/'
	if not os.path.exists(outputPath):
		os.makedirs(outputPath)
	alpha = numpy.random.randn(1, 200).tolist()[0]
	beta = numpy.random.randn(1, 200).tolist()[0]
	numpy.savez(outputPath + 'Face' + str(faceNumber) + '_coefs.npz', alpha=alpha, beta=beta)
	newFace(alpha, beta)
	write(outputPath, 0, 0, 'None0', '')
	# for occluder in ['Bars', 'Fence', 'Curtain', 'Door', 'Blinds']:
	# 	hideAll()
	# 	for occlusionLevel in range(1, 21):
	# 		parameterize(occluder, outputPath, 0, 0, occlusionLevel)
	# 		write(outputPath, 0, 0, occluder + str(occlusionLevel), '')



	hideAll_inference()
	print(len(identity))
	if len(identity) == 1:
		identity = identity.tolist()[0]
		print('Converted to list of length ', len(identity), sep='')
	# print(identity)
	print(str(outputBase + tempPath + name))
	alpha = identity[:200]
	beta = identity[200:]
	# print('alpha: ', alpha)
	# print('beta: ', beta)
	print('Received coefs:', len(alpha), len(beta))
	print('tempPath: ', '/om' in tempPath, tempPath)
	parameterize(occluder, outputBase + tempPath, 0, 0, occlusionLevel)
	newFace(alpha, beta)
	write(outputBase + tempPath if '/om/' not in tempPath else tempPath, name)
	













Exemple #4
0
def newFace(numIterations, sweep, numRecorded):
	time1_newFace = time.clock()
	print('before loading .npy files: ', count, ' mem usage: ', process.get_memory_info()[0] / float(2 ** 20)) 
	# alpha = [float(i) for i in '-0.92966973  0.69518502 -0.8981547  -0.34589304  0.12610498  0.67851812 0.89672588 -0.66787243  1.05074529 -1.22712534 -0.95795232  0.93538037 0.24038727  2.01223084  0.44020036  1.38685623  0.24048464 -0.40516621 0.20963966  0.62890887 -0.14917299 -0.56856491  0.35412225  0.46990665 -0.97240942  0.16997313 -0.65682486  1.64953287  0.42741089  0.31123165 -0.51002817  0.72892714  0.25298124 -0.30329086  0.80229401 -1.04072544 -0.76428976  1.31476733  0.77398871  0.0720638  -0.44638808  1.47925906 1.03075615 -0.0602049  -0.37425382 -0.15013765 -1.4017251  -0.15156402 -1.20320803 -0.99061562  1.91765218  0.34059112 -0.65708372  0.55523748 2.57600062  1.49741598  0.47213684  0.58038671 -0.42489875  0.78222819 2.05522305  0.40789688  0.31245369  0.35149993  0.24244021  2.11141546 -1.94649133 -1.36758977 -1.14849672  0.44214424 -0.50639208  0.11164741 0.97273858  0.43106336 -1.26547133  1.15725716  2.56604489  0.95316878 -0.54745507 -2.14853475 -1.27374172 -0.15686227 -0.56305927  1.76486959 0.1852892   0.22259218 -1.25602121 -0.67691762 -0.12030114  0.68691791 0.98907511 -0.48516922 -1.63471872  0.72012096 -0.6309221   1.354902 -1.98948079  0.15943147  0.81888061  0.40415338 -1.22252461 -0.82367678 0.54461056  1.21981972 -0.41660027  0.49547362  0.09677784  1.03633551 -0.23876583 -0.58596368 -0.05548121  1.00233203  1.63019563 -0.43893226 -0.22786099  0.53306099  1.54915535 -0.57277155 -1.91116553  1.8307214 0.50433634  0.01377692 -0.20098031 -0.37126117  0.34929356  0.97231942 0.83335677  1.01086688  0.07533074  0.4694385  -0.21772961  0.65581371 0.67545798 -1.05102824 -0.20334329  1.83573736  0.23865782 -0.04902131 0.40538378 -0.17200195 -1.00518945 -0.09464552  1.1870822   0.39655466 -0.03151129  0.851074   -2.37627443 -0.89822713 -1.46380954 -0.67938785 1.69464052  0.98143772  1.51974522  1.02925274 -0.17185041  0.10505381 -1.68307756 -0.74529892  2.86493505  0.87447933  1.08764024  0.64370426 1.35025104 -1.99849946 -0.14983732 -0.48705111  0.68987356  0.82243199 -0.87012301 -0.67259229  1.30474402 -1.02607697 -0.54475534 -1.16248686 0.74116009  0.96721691 -0.52501355 -0.76215131  0.25669687 -0.22644351 -0.28300505  0.62518625 -0.42029491 -0.94532153 -0.66083208  0.11463243 -0.34130686 -1.27382756 -0.49439186 -0.19980934 -0.83610859 -0.6394006 -0.76449523 -0.76767586  0.22853987  1.44579487  0.27170432 -0.5805581 1.18592102 -0.40798565'.split(' ') if len(i) > 0]
 #    beta = [float(i) for i in '-2.61219800e+00  -7.39388626e-01  -2.55480698e-01  -1.36944273e+00 1.93832359e-01  -1.01539438e+00   9.59703441e-01  -8.52303883e-0 -8.14540476e-01  -3.85862257e-01  -1.06064282e+00   6.49773898e-0 -1.48390393e+00  -9.78827093e-02   3.85220902e-01   1.88873405e+00 8.93706621e-02  -5.93855780e-01  -7.63549089e-01   7.09666365e-01 8.25413598e-01  -8.80468372e-01  -3.11979669e-02   8.32058521e-02 -9.67198925e-01  -9.97091530e-01  -9.05063893e-01  -1.40555920e+00 8.54965901e-01   5.90325658e-01   2.28359092e-01  -1.22979112e+00 1.17465866e+00  -9.39618219e-01   6.10932735e-02  -1.36251052e+00 -7.85183939e-01   1.11363074e+00   5.12473254e-01   1.92659996e-01 1.10491930e-01  -1.44159967e-01   3.80183285e-01   1.69090467e+00 -1.21154964e+00   1.10097624e+00  -1.01370160e+00   1.82894624e+00 4.87099137e-01   1.16506353e+00   1.15951420e-01   9.66076475e-01 1.73732951e-01  -2.42826561e-01  -6.07711429e-01  -6.46441139e-01 5.16189022e-01  -2.54364509e-01   1.17501091e+00  -8.21101673e-01 4.44734948e-01  -2.35028130e-01   2.99610062e-01  -3.87063595e-01 6.73282415e-01  -1.66462494e+00   4.96643688e-01  -1.64098409e+00 -4.07629810e-01   1.25663422e+00   1.46592629e-01  -1.13800284e+00 1.14736327e-01  -2.05627653e-01   2.29650132e-01  -8.64727189e-01 -1.21359903e+00   5.20212484e-01  -1.05562362e-03  -1.34660009e-01 -1.99478864e-01   9.02168738e-01  -1.29416398e+00   1.74120573e-01 3.26522730e-02   6.48949218e-01   3.89689891e-01  -7.94147479e-03 8.20858973e-01   3.05777459e-01  -9.52330555e-01   6.53437979e-01 3.16343002e-01  -9.44889264e-02  -1.81069784e-01   4.10982547e-01 6.63933929e-02  -1.14758358e+00   1.15730025e+00   1.87754040e+00 2.31189690e-01  -2.49790529e+00  -2.85539495e-01  -6.55994900e-02 -2.03871970e+00  -6.47195016e-01  -3.44623100e-01  -3.58329006e-01 3.15535548e-01  -1.21115409e-01   8.53642281e-01   4.86982092e-01 -1.24068321e+00  -8.83853446e-01  -9.79920837e-01   2.29804381e-01 -8.93408626e-01   6.77112918e-01   1.51256205e-01  -1.29680893e-01 -7.16531512e-01   5.39653073e-01   6.64529646e-01  -9.57776460e-01 2.00153814e+00  -1.39884861e+00   1.60241319e+00  -3.12756460e-01 -5.44844456e-01   3.35026763e-02  -2.53322960e+00   7.64123983e-01 3.18486468e-01  -1.90332885e-01  -4.07571493e-01  -6.26217663e-01 2.94207616e-01   1.96160523e+00  -1.43765584e+00  -1.47696600e+00 -7.92765446e-01  -1.38156869e+00   9.13668781e-01   6.99705236e-02 -1.14802488e+00  -1.68207111e-01  -2.92960848e-01   1.16157805e+00 4.79496375e-01  -2.02932687e-01  -1.54839489e-01   1.34063974e+00 6.83679608e-01  -1.31796941e+00   1.82587645e-01   1.69969180e+00 1.04312816e-01   3.95657011e-01   4.02621008e-02   5.13880609e-0 -1.65696241e+00  -8.43775201e-01   7.40550991e-01   6.20424044e-01 1.01025799e+00  -2.40483033e-01   6.79036541e-01  -2.63703913e-01 2.96794975e-01  -1.58310090e-01   1.05526470e+00   5.79248645e-01 6.82383156e-01   1.16736626e+00   2.19038861e-01  -1.67593885e+00 7.36853807e-01  -7.04699321e-01  -1.28651790e+00   2.84228367e+00 -1.11104478e-01   8.95072807e-01  -1.08449398e+00   3.52398983e-01 -4.35254949e-01  -1.52684760e+00   1.21508293e+00  -8.08533811e-02 -2.11891705e+00   1.99393907e-01   6.30220200e-01   7.42571073e-01 -1.16405750e+00  -3.19784566e-01  -4.99195743e-01   1.02079215e-02 3.55016460e-01   1.25309426e+00  -1.04477685e+00  -8.32856451e-01'.split(' ') if len(i) > 0]
	# shape_mat = numpy.array(coef2object(alpha_mat, shapeMU, shapePC, shapeEV, segMM, segMB, 4))
	# tex_mat = numpy.array(coef2object(beta_mat, texMU, texPC, texEV, segMM, segMB, 4))
	# shape_mat = numpy.load(outputPath + 'alpha.npy')
	# tex_mat = numpy.load(outputPath + 'beta.npy')
	# vertices = numpy.load(tempDir + 'alpha.npy')
	# colors = numpy.load(tempDir + 'beta.npy')
	print('loading', tempDir + 'alpha.npy')
	print(os.path.exists(tempDir + 'alpha.npy'))
	alpha_mat = numpy.load(tempDir + 'alpha.npy').tolist()
	# alpha_mat = eval(sys.stdin.readline().strip())
	timet_1 = time.clock()
	beta_mat = numpy.load(tempDir + 'beta.npy').tolist()
	# beta_mat = eval(sys.stdin.readline().strip())
	timet_2 = time.clock()
	global alpha_old
	global beta_old
	print('alpha: ', alpha_mat)
	# print('alpha_old', alpha_old)
	print('alpha changed: ', alpha_mat != alpha_old)
	print('beta: ', beta_mat)
	print('beta_changed: ', beta_mat != beta_old)
	# print('beta_old: ', beta_old)
	alpha_old = alpha_mat
	beta_old = beta_mat
	print('BEFORE COEF2OBJ ALPHA: ', count, ' mem usage: ', process.get_memory_info()[0] / float(2 ** 20)) 
	shape_mat = numpy.array(coef2object(alpha_mat, shapeMU, shapePC, shapeEV, segMM, segMB, 4))
	timet_3 = time.clock()
	print('AFTER COEF2OBJ ALPHA: ', count, ' mem usage: ', process.get_memory_info()[0] / float(2 ** 20)) 
	print('BEFORE COEF2OBJ BETA: ', count, ' mem usage: ', process.get_memory_info()[0] / float(2 ** 20)) 
	tex_mat = numpy.array(coef2object(beta_mat, texMU, texPC, texEV, segMM, segMB, 4))
	print('AFTER COEF2OBJ BETA: ', count, ' mem usage: ', process.get_memory_info()[0] / float(2 ** 20)) 
	tex_mat=tex_mat.swapaxes(0, 1)
	tex_mat.shape=(53490, 3)
	timet_4=time.clock()
	vertices = blenderMesh(shape_mat)
	colors = blenderColors(tex_mat, tl)
	timet_5 = time.clock()
	print("time for loading alpha: ", timet_1-time1_newFace)
	print("time for loading beta: ", timet_2-timet_1)
	print("time for converting alpha to shape: ", timet_3-timet_2)
	print("time for converting beta to tex: ", timet_4-timet_3)
	print("time for convering shape + tex to vertices + colors: ", timet_5-timet_4)

	# timet_1 = time.clock()
	# bytes_size = int(p.stdout.readline().strip().decode('utf-8'))
	# timet_2 = time.clock()
	# vertices_bytes = p.stdout.read(bytes_size)#.decode('utf-8')#23452861#3776141
	# # vertices = pickle.loads(vertices_bytes)
	# timet_3 = time.clock()
	# vertices = eval(vertices_bytes)
	# print('vertices eval: ', type(vertices), len(vertices), len(vertices[0]), type(vertices[0][0]), '0: ', vertices[0][0], ':4: ', vertices[:4])
	# print("vertics_bytes: ", type(vertices_bytes), vertices_bytes[:100])
	# # vertices = list(vertices_bytes)
	# timet_4 = time.clock()
	# bytes_size = int(p.stdout.readline().strip().decode('utf-8'))
	# timet_5 = time.clock()
	# colors_bytes = p.stdout.read(bytes_size)#3746640#3776996
	# # colors = pickle.loads(colors_bytes)
	# timet_6 = time.clock()
	# colors = eval(colors_bytes)
	# timet_7 = time.clock()
	# print('time for reading alpha size: ', timet_2-timet_1)
	# print('time for reading alpha: ', timet_3-timet_2)
	# print('time for eval alpha string: ', timet_4-timet_3)
	# print('time for reading beta size: ', timet_5-timet_4)
	# print('time for reading beta: ', timet_6-timet_5)
	# print('time for eval beta string: ', timet_7-timet_6)
	# print('after loading .npy files: ', count, ' mem usage: ', process.get_memory_info()[0] / float(2 ** 20)) 
	time_0 = time.clock()

	# tex_mat=tex_mat.swapaxes(0, 1)
	# tex_mat.shape=(53490, 3)
	# vertices = blenderMesh(shape_mat)
	# colors = blenderColors(tex_mat, tl)

	modifyMesh(vertices, colors)
	time2_newFace = time.clock()
	global time_newFace
	time_newFace = time2_newFace - time1_newFace
	print('time to receive shape + tex: ', time_0-time1_newFace)
	print('modifyMesh: ', time2_newFace-time_0)
	print('####time in newFace: ', time_newFace)
	write(tempDir, 0, 0, 'None', (sweep//8)%numRecorded)
Exemple #5
0
	# 	tempDir = sys.stdin.readline().strip()
	# 	print(tempDir)
	time_iteration_1 = time.clock()
	print('Sweep: ', sweep, ', Sigma: ', sigma, ', Count: ', count, sep = '')
	print('count: ', count, ' mem usage: ', process.get_memory_info()[0] / float(2 ** 20)) 
	coefsFromJulia()
	time_co = time.clock()
	print('Rendering: ', count, ' (', sweep//8, ' / ', numIterations, ')', sep = '')
	newFace(numIterations, sweep, numRecorded)
	
	# recordCoefs(outputPath, alpha_mat, beta_mat, occLevel, count)
	#print('recorded: ', count)
	if sweep == numIterations*8 - 1:
		if occLevel > 0:
			hideAll_inference()
			write(tempDir, 0, 0, '_noOccluder', sweep//8)
			parameterize(occluder, outputPath, 0, 0, occLevel)
			write(tempDir, 0, 0, '_final', sweep//8)
	if sweep == 7:
		write(tempDir, 0, 0, 'init', sweep//8)
	
	time_1 = time.clock()
	inferredImgArr = readImg(tempDir, occLevel, (sweep//8)%numRecorded, 'inf')
	time_2 = time.clock()
	print('pre-inf-image')
	llscore = float(sum(scipy.stats.norm.logpdf(obsImgArr,inferredImgArr, sigma))[0])
	print('post-inf-image')
	time_3 = time.clock()
	pxerror = numpy.linalg.norm(inferredImgArr - obsImgArr)/inferredImgArr.size
	time_send = time.clock()
	# updatellArray(outputPath, llArray, llscore, pxArray, pxerror, numIterations, count)