loader=jinja2.FileSystemLoader('./')).get_template('template.html') savedNet = sys.argv[1] testParamPath = sys.argv[2] gpuid = int(sys.argv[3]) resultfolder, modelfile = os.path.split(savedNet) #Load test params test_params = {} test_params = loadParams(testParamPath) outputFolder = resultfolder + r'/test_{}'.format(test_params['outtag']) if (os.path.exists(outputFolder) == False): os.makedirs(outputFolder) OnlineRender = FastRenderEngine(0) OnlineRender.SetGeometry('Sphere') #params['geometryPath'], True, '') OnlineRender.PreLoadAllLight(r'{}/light.txt'.format( params['envMapFolder'])) fovRadian = 60.0 / 180.0 * math.pi cameraDist = 1.5 / (math.tan(fovRadian / 2.0)) OnlineRender.SetCamera(0, 0, cameraDist, 0, 0, 0, 0, 1, 0, fovRadian, 0.01, 100, 128, 128) OnlineRender.SetSampleCount(128, 512) renderContext['experimentTag'] = savedNet random.seed(23333) np.random.seed(23333) caffe.set_random_seed(23333)
if(len(sys.argv) == 9): out_root = sys.argv[8] else: out_root = data_root labeled_file_in = data_root + r'/{}/Labeled/trainingdata.txt'.format(data_tag) test_file_in = data_root + r'/{}/Test/test.txt'.format(data_tag) rendered_labeled_out = out_root + r'/{}/Labeled'.format(data_tag) rendered_test_out = out_root + r'/{}/Test'.format(data_tag) specular_file = data_root + r'/{}/Labeled/specroughness.txt'.format(data_tag) lightpool_file = params_global['envMapFolder'] + r'/lightPool_{}.dat'.format(data_tag) AugmentRender = FastRenderEngine(gpuid) AugmentRender.SetGeometry('Plane') AugmentRender.PreLoadAllLight(r'{}/light.txt'.format(params_global['envMapFolder'])) AugmentRender.SetSampleCount(128, 1024) fovRadian = 60.0 / 180.0 * math.pi cameraDist = 1.0 / (math.tan(fovRadian / 2.0)) AugmentRender.SetCamera(0, 0, cameraDist, 0, 0, 0, 0, 1, 0, fovRadian, 0.01, 100, 384, 384) specList_final = {} roughnessList_final = {} with open(specular_file, 'r') as f: rawList = f.read().strip().split('\n') for t in rawList: mid = int(t.split(',')[0]) spec = float(t.split(',')[1]) roughness = float(t.split(',')[2])
testAlbedo = np.linspace(0.1, 0.95, albedoCnt - 1) testSpec = np.linspace(0.1, 0.95, specCnt - 1) testRoughness = np.exp( np.linspace(math.log(0.03), math.log(0.87), roughnessCnt - 1)) imageCnt = albedoCnt * specCnt * roughnessCnt * thetaCnt * phiCnt envMapFolder = params['envMapFolder'] with open(envMapFolder + '/light.txt', 'r') as f: lightID = map(int, f.read().strip().split('\n')) lightID = list(np.array(lightID) - 1) np.random.seed(gpuid) OnlineRender = FastRenderEngine(gpuid) OnlineRender.SetGeometry('Sphere') OnlineRender.PreLoadAllLight(r'{}/light.txt'.format(envMapFolder)) fovRadian = 60.0 / 180.0 * math.pi cameraDist = 1.5 / (math.tan(fovRadian / 2.0)) OnlineRender.SetCamera(0, 0, cameraDist, 0, 0, 0, 0, 1, 0, fovRadian, 0.01, 100, 128, 128) OnlineRender.SetSampleCount(128, 1024) OnlineRender.SetRenderMode(0) albedoCnt = len(trainAlbedo) specCnt = len(trainSpec) roughnessCnt = len(trainRoughness) trainCube = np.zeros((albedoCnt, specCnt, roughnessCnt, 3)) testCube = np.zeros((albedoCnt - 1, specCnt - 1, roughnessCnt - 1, 3))
imgbatch[i, :, :, :] = autoExposure(imgbatch[i, :, :, :]) imgbatch = imgbatch.transpose([0,2,3,1]) pipe.send(imgbatch) counter = counter + batchSize posInDataSet = (posInDataSet + batchSize) % dataset.dataSize newepoch = counter / dataset.dataSize if(newepoch != epoch): dataset.shuffle() epoch = newepoch # init fast online renderer onlineRender = FastRenderEngine(params['rendergpuid']) onlineRender.SetGeometry('Plane') onlineRender.SetSampleCount(128, 512) onlineRender.PreLoadAllLight(r'{}/light.txt'.format(params['envMapFolder'])) fovRadian = 60.0 / 180.0 * np.pi cameraDist = 1.0 / (math.tan(fovRadian / 2.0)) onlineRender.SetCamera(0, 0, cameraDist, 0, 0, 0, 0, 1, 0, fovRadian, 0.01, 100, 256, 256) # set random seeds random.seed(params['randomSeed']) tf.set_random_seed(params['randomSeed']) np.random.seed(params['randomSeed']) # init tensorflow network
for id, lid in enumerate(lightID): lightIDToEnumerateID[lid] = id if __name__ == '__main__': modelFile = sys.argv[1] testSetPath = sys.argv[2] gpuid = int(sys.argv[3]) imgw = 256 fovRadian = 60.0 / 180.0 * math.pi cameraDist = 1.0 / (math.tan(fovRadian / 2.0)) cameraDist_1 = 1.5 / (math.tan(fovRadian / 2.0)) RelightingRender = FastRenderEngine(gpuid) RelightingRender.SetGeometry('Plane') RelightingRender.SetCamera(0, 0, cameraDist, 0, 0, 0, 0, 1, 0, fovRadian, 0.01, 100, 256, 256) RelightingRender.SetSampleCount(128, 512) RelightingRender.PreLoadAllLight(r'{}/light.txt'.format( params_global['envMapFolder'])) caffe.set_mode_gpu() caffe.set_device(gpuid) path, file = os.path.split(modelFile) modelFolder = path testnet = caffe.Net(path + r'/net_test.prototxt', caffe.TEST) testnet.copy_from(modelFile) path, file = os.path.split(testSetPath) with open(testSetPath, 'r') as f: