示例#1
0
def check_quality(result, log_path, global_step):
    img_path = log_path + "imgs_{}/".format(global_step)
    make_dir(img_path)
    np.savetxt(img_path + "param_ground_truth.csv", result[2], delimiter=',')
    # np.savetxt(img_path+"param_guessed.csv",result[3],delimiter=',')
    np.savetxt(img_path + "position_ground_truth.csv",
               result[3],
               delimiter=',')
    np.savetxt(img_path + "n_dot_view.csv",
               result[4].reshape([-1, 1]),
               delimiter=',')
    np.savetxt(img_path + "view_dir.csv",
               result[5].reshape([-1, 3]),
               delimiter=',')
    np.savetxt(img_path + "n.csv", result[6].reshape([-1, 3]), delimiter=',')
    np.savetxt(img_path + "n_local.csv",
               result[7].reshape([-1, 3]),
               delimiter=',')
    # np.savetxt(img_path+"param_origin.csv",result[5],delimiter=',')
    # np.savetxt(img_path+"position_guessed.csv",result[5],delimiter=',')
    for idx, a_gt_lumi in enumerate(result[0]):
        gt_lumi_img = visualize_new(a_gt_lumi.reshape([-1]), scalerf=255.0)
        guessed_lumi_img = visualize_new(np.exp(result[1][idx].reshape([-1])) -
                                         1,
                                         scalerf=255.0)
        cv2.imwrite(img_path + "{}_gt.png".format(idx), gt_lumi_img)
        cv2.imwrite(img_path + "{}_guessed.png".format(idx), guessed_lumi_img)
        np.savetxt(img_path + "{}_mm.csv".format(idx),
                   result[2][idx].reshape([-1, 1]),
                   delimiter=',')
示例#2
0
 def saveWLog(self,globalStep,tmp_log_path):
     W = self.sess.run(self.end_points['projection_matrix'])
     W_vector = W.reshape([-1])
     f = open(tmp_log_path+"W_{}.csv".format(globalStep),"w")
     [f.write("{},\n".format(W_vector[i]))  for i in range(W_vector.shape[0])]
     f.close()
     W = W.T
     for i in range(W.shape[0]):
         one_pattern = visualize_new(W[i]/W[i].max(),scalerf=255)#cook10240(W[i])#visualize(W[i]/W[i].max(),scalerf=255)
         one_pattern = np.expand_dims(one_pattern,axis = -1)
         one_pattern_pos = np.maximum(one_pattern,0.0)
         one_pattern_neg = np.minimum(one_pattern,0.0)*-1
         one_pattern = np.concatenate([one_pattern_neg,np.zeros(one_pattern.shape),one_pattern_pos],axis = -1)
         # one_pattern /= one_pattern.max()
         cv2.imwrite(tmp_log_path+"{}.png".format(i),one_pattern)
示例#3
0
    def check_quality(self,val_data):
        results = self.sess.run([
            self.end_points["ground_truth_lumitexels_direct"],
            self.end_points["guessed_lumitexels_pd"],
            self.end_points["ground_truth_slice_pd"],
            self.end_points["guessed_lumitexels_ps"],
            self.end_points["ground_truth_slice_ps"],
            self.end_points["ground_truth_slice_length"],
            self.end_points["ps_predicted"],
            self.end_points["light_dir"],
            self.end_points["view_dir"],
            self.end_points["normal"],
            self.end_points["pos"],#12



            self.end_points['projection_matrix']
            # self.end_points["n_local_gt"],
            # self.end_points["guessed_normal"],
            # self.end_points["pd_gt"],
            # self.end_points["guessed_pd"],
        ],feed_dict={
            self.end_points["input_params"]:val_data[0],
            self.end_points["input_positions"]:val_data[1],
            self.end_points["istraining"]:False,
            self.end_points["input_rotate_angles"]:val_data[2]
        })

        _,img_height,img_width,_ = self.check_images.shape.as_list()
        img_width = img_width//5
        check_img_buffer = np.zeros([self.batch_size*5,img_height,img_width],np.float32)
        for idx,a_gt_lumi in enumerate(results[0]):

            # pos = results[12][idx]
            # view_dir = results[10][idx]  #[1,3]
            # light_dir = results[9][idx] #[lumi_size, 3]
            # n = results[11][idx]


            tmp = visualize_new(a_gt_lumi.reshape([-1]),scalerf=255.0)
            check_img_buffer[idx*5+0] = tmp
            check_img_buffer[idx*5+1] = expand_img(visualize_cube_slice(results[1][idx].reshape([-1]),sample_num=8,scalerf=255.0),8,"copy_only")
            check_img_buffer[idx*5+2] = expand_img(visualize_cube_slice(results[2][idx].reshape([-1]),sample_num=8,scalerf=255.0),8,"copy_only")

            a = results[4][idx].reshape([-1])
            tmp = visualize_cube_slice(a/a.max(),sample_num=64,scalerf=2550.0)
            cv2.putText(tmp, '{:.2f}'.format(results[5][idx][0]), (128,64), cv2.FONT_HERSHEY_SIMPLEX, 1.2, 255, 2)
            check_img_buffer[idx*5+4] = tmp

            a = results[3][idx].reshape([-1])/a.max()
            tmp = visualize_cube_slice(a,sample_num=64,scalerf=2550.0)
            cv2.putText(tmp, '{:.2f}'.format(results[6][idx][0]), (128,64), cv2.FONT_HERSHEY_SIMPLEX, 1.2, 255, 2)
            check_img_buffer[idx*5+3] = tmp
            

        
        check_img_buffer = np.transpose(check_img_buffer,axes=[1,0,2])
        check_img_buffer = np.reshape(check_img_buffer,[check_img_buffer.shape[0],self.batch_size,-1])
        check_img_buffer = np.transpose(check_img_buffer,axes=[1,0,2])
        check_img_buffer = np.expand_dims(check_img_buffer,axis=-1)
        check_img_buffer = np.minimum(check_img_buffer,255.0)
        check_img_buffer = np.maximum(check_img_buffer,0.0)

        self.check_images.load(check_img_buffer.astype(np.uint8),self.sess)
        # self.check_formfactor.load(check_img_ff_buffer.astype(np.uint8),self.sess)

        W = results[-1]
        W = W.T
        pattern_buffer = np.zeros([self.measurements_length,img_height,img_width,3],np.float32)
        for i in range(W.shape[0]):
            one_pattern = visualize_new(W[i]/W[i].max(),scalerf=255)#cook10240(W[i])#visualize(W[i]/W[i].max(),scalerf=255)
            one_pattern = np.expand_dims(one_pattern,axis = -1)
            one_pattern_pos = np.maximum(one_pattern,0.0)
            one_pattern_neg = np.minimum(one_pattern,0.0)*-1
            pattern_buffer[i] = np.concatenate([one_pattern_neg,np.zeros(one_pattern.shape),one_pattern_pos],axis = -1)
        

        pattern_buffer = np.minimum(pattern_buffer,255.0)
        pattern_buffer = np.maximum(pattern_buffer,0.0)

        self.pattern_check.load(pattern_buffer.astype(np.uint8),self.sess)

        summary,global_step = self.sess.run([
            self.end_points["check_summary"],
            self.end_points["global_step"]
        ])
        self.end_points["writer"].add_summary(summary,global_step)



        return results
示例#4
0
    def draw_train_net(self,net_name,projectionMatrix_trainable):
        '''
        net_name: a string,the name of this net
        '''
        with tf.variable_scope(net_name,reuse=tf.AUTO_REUSE):
            #[1]define input parameters
            input_params = tf.placeholder(tf.float32,shape=[self.batch_size,self.parameter_len],name="input_params")
            self.end_points["input_params"] = input_params
            input_positions = tf.placeholder(tf.float32,shape=[self.batch_size,3],name="render_positions")
            self.end_points["input_positions"] = input_positions
            input_rotate_angles = tf.placeholder(tf.float32,shape=[self.batch_size,1],name="rotate_angles")
            self.end_points["input_rotate_angles"] = input_rotate_angles
            isTraining = tf.placeholder(tf.bool,name = "isTraining_ph")
            self.end_points["istraining"] = isTraining
            
            #[2]draw rendering net,render ground truth 
            renderer = tf_ggx_render(self.end_points["standard_rendering_parameters"])
            self.renderer = renderer

            slice_rendering_parameters = self.end_points["standard_rendering_parameters"].copy()
            slice_rendering_parameters["config_dir"] = "auxiliary/tf_ggx_render_newparam/tf_ggx_render_configs_cube_slice_64x64/"
            slice_rendering_parameters["lumitexel_size"] = self.slice_length_ps
            renderer_slice_ps = tf_ggx_render(slice_rendering_parameters)

            slice_rendering_parameters = self.end_points["standard_rendering_parameters"].copy()
            slice_rendering_parameters["config_dir"] = "auxiliary/tf_ggx_render_newparam/tf_ggx_render_configs_cube_slice_8x8/"
            slice_rendering_parameters["lumitexel_size"] = self.slice_length_pd
            renderer_slice_pd = tf_ggx_render(slice_rendering_parameters)
            
            rotate_theta_zero = tf.zeros([self.batch_size,1],tf.float32)
            ground_truth_lumitexels_direct = renderer.draw_rendering_net(input_params,input_positions,rotate_theta_zero,"ground_truth_renderer_direct")#[batch,lightnum,1]
            ground_truth_lumitexels_direct *= self.RENDER_SCALAR
            self.end_points["ground_truth_lumitexels_direct"] = ground_truth_lumitexels_direct

            ground_truth_slice_ps = renderer_slice_ps.draw_rendering_net(input_params,input_positions,rotate_theta_zero,"ground_truth_renderer_cube_slice_ps",pd_ps_wanted="ps_only")
            ground_truth_slice_ps = ground_truth_slice_ps*self.SLICE_SCALAR
            self.end_points["ground_truth_slice_ps"] = ground_truth_slice_ps    

            ground_truth_slice_pd = renderer_slice_pd.draw_rendering_net(input_params,input_positions,rotate_theta_zero,"ground_truth_renderer_cube_slice_pd",pd_ps_wanted="pd_only")
            ground_truth_slice_pd = ground_truth_slice_pd*self.SLICE_SCALAR
            self.end_points["ground_truth_slice_pd"] = ground_truth_slice_pd      

            
            # n_local,_ = renderer.get_n("ground_truth_renderer_direct")
            # self.end_points["n_local_gt"] = n_local
            # pd = renderer.get_pd("ground_truth_renderer_direct")
            # self.end_points["pd_gt"] = pd

            #[3]draw linear projection layer
            with tf.variable_scope('linear_projection',reuse = tf.AUTO_REUSE):
                kernel = tf.get_variable(name = 'projection_matrix',
                                        trainable=projectionMatrix_trainable,
                                        shape = [self.lumitexel_length,self.measurements_length],
                                        initializer=tf.contrib.layers.xavier_initializer()
                                        )#[lightnum,measure_ments]
                self.end_points['projection_matrix_origin'] = kernel
                kernel = tf.transpose(kernel,perm=[1,0])
                kernel = tf.nn.l2_normalize(kernel,axis=1)
                kernel = tf.transpose(kernel,perm=[1,0])
                self.end_points['projection_matrix'] = kernel


                measure_ments = tf.matmul(tf.squeeze(ground_truth_lumitexels_direct,axis=2),kernel)#[batch,measure_ments]
            
            #[3.1]noiser
            with tf.variable_scope("noiser"):
                noise = tf.random_normal(tf.shape(measure_ments),mean = 0.0,stddev = 0.01,name="noise_generator")+1.
                measure_ments_noised = tf.multiply(measure_ments,noise)
            
            # measure_ments_noised_theta = tf.concat([measure_ments_noised,tf.sin(input_rotate_angles),tf.cos(input_rotate_angles)],axis=-1)
            #[4]draw guesser net
            guessed_lumitexels_pd,guessed_lumitexels_ps,ps_predicted,p_predicted = self.draw_param_guesser(measure_ments_noised,"param_guesser",renderer,isTraining)#[batch,param_length]
            
            self.end_points["ps_predicted"] = ps_predicted
            
            guessed_lumitexels_pd = tf.expand_dims(guessed_lumitexels_pd,axis=-1)
            self.end_points["guessed_lumitexels_pd"] = guessed_lumitexels_pd

            guessed_lumitexels_ps = tf.expand_dims(guessed_lumitexels_ps,axis=-1)
            self.end_points["guessed_lumitexels_ps"] = tf.exp(guessed_lumitexels_ps)-1.0


            predicted_normal = self.draw_normal_net(measure_ments_noised,"normal_net",renderer,isTraining)
            _,label_normal = renderer.get_n("ground_truth_renderer_direct")

            self.end_points["wi"] = renderer.get_wi("ground_truth_renderer_direct")
            self.end_points["light_dir"] = self.end_points["wi"]
            self.end_points["pos"] = input_positions
            self.end_points["view_dir"] = renderer.get_compute_node("ground_truth_renderer_direct","view_dir_rotated")
            self.end_points["normal"] = renderer.get_compute_node("ground_truth_renderer_direct","normal")


            # self.end_points["guessed_normal"] = normal_guessed
            # self.end_points["guessed_pd"] = pd_guessed

            # guessed_n,guessed_t,guessed_axay,guessed_pd,guessed_ps = tf.split(guessed_params,[3,3,2,1,1],axis=-1)
            # guessed_axay = tf.clip_by_value(guessed_axay,0.006,0.503)
            # guessed_pd = tf.clip_by_value(guessed_pd,0.0,1.0)
            # guessed_ps = tf.clip_by_value(guessed_ps,0.0,10.0)
            # guessed_params = tf.concat([guessed_n,guessed_t,guessed_axay,guessed_pd,guessed_ps],axis=-1)
            # self.end_points["guessed_params"] = guessed_params
            # # self.end_points["guessed_position"] = guessed_position
            # #[5]render guessed lumitexel
            # guessed_lumitexels = renderer.draw_rendering_net(guessed_params,input_positions,"guessed_renderer")#[batch,lightnum,1]
            # # guessed_lumitexels = renderer.draw_rendering_net(guessed_params,input_positions,"guessed_renderer")#[batch,lightnum,1]
            # guessed_lumitexels = guessed_lumitexels*self.RENDER_SCALAR
            # self.end_points["guessed_lumitexels"] = guessed_lumitexels
            
        # _,self.end_points["n_dot_view"],self.end_points["view_dir"],self.end_points["n"],self.end_points["n_local"] = renderer.get_n_dot_view_penalty("ground_truth_renderer")
        #[6]define loss

        ##########################
        ######pd loss
        #########################
        l2_loss_pd = tf.nn.l2_loss(guessed_lumitexels_pd-ground_truth_slice_pd,"l2_loss_pd")
        self.end_points["l2_loss_pd"] = l2_loss_pd

        ##########################
        ######ps loss
        #########################
        #----------part 1
        if self.loss_configs["use_weight"]:
            print("nonono")
            exit(-1)
            assert self.loss_configs["use_log"] == False
            ground_truth_slice_ps_tmp = tf.reshape(ground_truth_slice_ps,[self.batch_size,self.slice_length_ps])
            weights = 1.0/tf.reduce_sum(tf.square(ground_truth_slice_ps_tmp),axis=-1,keepdims=True)#[batch,1]

            subed = ground_truth_slice_ps-guessed_lumitexels_ps
            subed = tf.reshape(subed,[self.batch_size,self.slice_length_ps])
            loss_tmp = tf.reduce_sum(tf.square(subed),axis=-1,keepdims=True)*weights
            l2_loss_ps = tf.reduce_sum(loss_tmp)/2.0

        elif self.loss_configs["use_dot"]:
            print("nonono")
            exit(-1)
            ground_truth_slice_ps_tmp = tf.reshape(ground_truth_slice_ps,[self.batch_size,self.slice_length_ps])
            guessed_slice_ps_tmp = tf.reshape(guessed_lumitexels_ps,[self.batch_size,self.slice_length_ps])
            
            ground_truth_slice_ps_tmp = tf.nn.l2_normalize(ground_truth_slice_ps_tmp,axis=-1)
            guessed_slice_ps_tmp = tf.nn.l2_normalize(guessed_slice_ps_tmp,axis=-1)
            l2_loss_ps = tf.reduce_sum(1.0-tf.reduce_sum(tf.multiply(ground_truth_slice_ps_tmp,guessed_slice_ps_tmp),axis=-1))

        elif self.loss_configs["use_log"]:
            print("nonono")
            exit(-1)
            l2_loss_ps = tf.nn.l2_loss(guessed_lumitexels_ps-tf.maximum(tf.log(1.0+ground_truth_slice_ps),0.0),"l2_loss_ps")
        elif self.loss_configs["use_l2"]:
            # ground_truth_slice_ps_tmp = tf.reshape(ground_truth_slice_ps,[self.batch_size,self.slice_length_ps])
            # guessed_slice_ps_tmp = tf.reshape(guessed_lumitexels_ps,[self.batch_size,self.slice_length_ps])
            
            # ground_truth_slice_ps_tmp = tf.nn.l2_normalize(ground_truth_slice_ps_tmp,axis=-1)
            # alpha = 1e3
            ground_truth_slice_ps_tmp = tf.log(1.0+ground_truth_slice_ps)
            guessed_slice_ps_tmp = guessed_lumitexels_ps
            self.end_points["guessed_lumitexels_ps_normalized"] = guessed_slice_ps_tmp
            self.end_points["ground_truth_slice_ps_normalized"] = ground_truth_slice_ps_tmp
            l2_loss_ps = tf.nn.l2_loss(ground_truth_slice_ps_tmp-guessed_slice_ps_tmp,"l2_loss_ps")

        else:
            print("[TAMER]undefined l2 loss of ps")
        self.end_points["l2_loss_ps"] = l2_loss_ps

        #------------part 2
        tmp = tf.squeeze(ground_truth_slice_ps_tmp,axis=2)
        ground_truth_slice_length = tf.sqrt(tf.reduce_sum(tf.square(tmp),axis=-1,keepdims=True))
        ground_truth_slice_length = tf.log(1+ground_truth_slice_length)
        self.end_points["ground_truth_slice_length"] = ground_truth_slice_length
        if self.with_length_predict:
            l2_loss_length = tf.nn.l2_loss(ps_predicted-ground_truth_slice_length,"l2_loss_normalized")
        else:
            l2_loss_length = 0.0
        self.end_points["l2_loss_length"] = l2_loss_length

        #-------------part 3
        l2_loss_p = tf.nn.l2_loss(p_predicted-input_positions,"l2_loss_p")
        self.end_points["p_loss"] = l2_loss_p

        ##########################
        ######normal loss
        #########################
        l2_loss_normal = tf.nn.l2_loss(predicted_normal - label_normal)
        self.end_points["l2_loss_normal"] = l2_loss_normal

        l2_loss = self.lambdas["pd"]*l2_loss_pd+self.lambdas["ps"]*l2_loss_ps+self.lambdas["ps_length"]*l2_loss_length+self.lambdas["normal"]*l2_loss_normal+self.lambdas["p"]*l2_loss_p

        # l2_loss_normal = tf.nn.l2_loss(n_local-normal_guessed,"l2_loss_normal")
        # self.end_points["l2_loss_normal"] = l2_loss_normal

        # l2_loss_pd = tf.nn.l2_loss(pd-pd_guessed,"l2_loss_pd")
        # self.end_points["l2_loss_pd"]=l2_loss_pd

        # l2_loss_param = tf.nn.l2_loss((input_params-guessed_params)*np.array([1,1,1,0,0,0,0,0,1,0.1]),"l2_loss_param")*1e3
        # l2_loss_pos = tf.nn.l2_loss((input_positions-guessed_position)*np.array([0.02,0.02,0.02]),"l2_loss_position")*1e3
        # l2_loss = tf.nn.l2_loss(tf.maximum(tf.log(1.0+guessed_lumitexels),0.0)-tf.maximum(tf.log(1.0+ground_truth_lumitexels),0.0),"l2_loss")
        # print(l2_loss)
        # n_3d,tangent_3d,ax,ay,pd,ps = tf.split(guessed_params,[3,3,1,1,1,1],axis=1)
        loss_k = 1e5
        if projectionMatrix_trainable:
            regularization_loss = renderer.regularizer_relu(kernel,-1.0,1.0,loss_k)
                                # renderer.regularizer_relu(guessed_position,-50.0,50.0,loss_k)+\    
                                # n_dot_view_penalty+\
                                # renderer.regularizer_relu(theta,0.0,math.pi,loss_k)+\
        else:
            regularization_loss = 0

        total_loss = l2_loss+regularization_loss#+l2_loss_normal+l2_loss_pd#+l2_loss_param+l2_loss_pos

        # all_trainable_variables = tf.get_collection_ref(tf.GraphKeys.TRAINABLE_VARIABLES)
        # for a_variable in all_trainable_variables:
        #     print(a_variable)
        # exit()

        #[7]define optimizer
        global_step = tf.Variable(0, name='global_step',trainable=False)
        self.end_points["global_step"] = global_step
        learning_rate =tf.Variable(self.learning_rate, name='learning_rate',trainable=False)
        update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
        with tf.control_dependencies(update_ops):
            optimizer = tf.train.AdamOptimizer
            optimizer = optimizer(learning_rate)
            self.trainHandler = optimizer.minimize(total_loss,global_step=global_step)
            self.end_points["optimizer"] = optimizer
        
        #[8]define others
        #[8.1] writer
        train_penalty_summary = tf.summary.scalar("loss_penalty_"+self.tamer_name,regularization_loss)
        train_l2_loss_summary = tf.summary.scalar("loss_l2_total_train_"+self.tamer_name,l2_loss)

        train_l2_loss_pd_summary = tf.summary.scalar("loss_pd_train_"+self.tamer_name,l2_loss_pd)
        train_l2_loss_pslength_summary = tf.summary.scalar("loss_pslength_train_"+self.tamer_name,l2_loss_length)
        train_l2_loss_ps_summary = tf.summary.scalar("loss_ps_train_"+self.tamer_name,l2_loss_ps)
        train_l2_loss_normal_summary = tf.summary.scalar("loss_normal_train_"+self.tamer_name,l2_loss_normal)
        train_l2_loss_p_summary = tf.summary.scalar("loss_p_train_"+self.tamer_name,l2_loss_p)
        
        val_l2_loss_summary = tf.summary.scalar("loss_l2_total_val_"+self.tamer_name,l2_loss)

        val_l2_loss_pd_summary = tf.summary.scalar("loss_pd_val_"+self.tamer_name,l2_loss_pd)
        val_l2_loss_pslength_summary = tf.summary.scalar("loss_pslength_val_"+self.tamer_name,l2_loss_length)
        val_l2_loss_ps_summary = tf.summary.scalar("loss_ps_val_"+self.tamer_name,l2_loss_ps)
        val_l2_loss_normal_summary = tf.summary.scalar("loss_normal_val_"+self.tamer_name,l2_loss_normal)
        val_l2_loss_p_summary = tf.summary.scalar("loss_p_val_"+self.tamer_name,l2_loss_p)
        # val_normal_l2_loss_summary = tf.summary.scalar("loss_normal_val_"+self.tamer_name,l2_loss_normal)
        # val_pd_l2_loss_summary = tf.summary.scalar("loss_pd_val_"+self.tamer_name,l2_loss_pd)
        
        

        tmp_zero_lumi = np.zeros(self.lumitexel_length,np.float32)
        tmp_zero_lumi_img = visualize_new(tmp_zero_lumi.reshape([-1]))
    
        zeros_lumis_init = tf.zeros_initializer()#tf.constant_initializer(zeros_lumis)

        self.check_images = tf.get_variable(name = 'check_pic',
                                        trainable=False,
                                        shape = [self.batch_size,tmp_zero_lumi_img.shape[0],tmp_zero_lumi_img.shape[1]*5,1],
                                        initializer=zeros_lumis_init,
                                        dtype=tf.uint8
                                        )#[lightnum,measure_ments]
        
        self.pattern_check = tf.get_variable(name = 'patterns',
                                        trainable=False,
                                        shape = [self.measurements_length,tmp_zero_lumi_img.shape[0],tmp_zero_lumi_img.shape[1],3],
                                        initializer=zeros_lumis_init,
                                        dtype=tf.uint8
                                        )

        # self.check_formfactor = tf.get_variable(name = 'check_pic_ff',
        #                                 trainable=False,
        #                                 shape = [self.batch_size,tmp_zero_lumi_img.shape[0],tmp_zero_lumi_img.shape[1],1],
        #                                 initializer=tf.zeros_initializer(),
        #                                 dtype=tf.uint8
        #                                 )#[lightnum,measure_ments]

        check_pic_summary = tf.summary.image("lumitexels",self.check_images,max_outputs=self.batch_size)
        pattern_summary = tf.summary.image("patterns",self.pattern_check,max_outputs=self.measurements_length)
        # check_pic_ff_summary = tf.summary.image("ff",self.check_formfactor,max_outputs=self.batch_size)
        
        
        #loss of matcher
        train_summary = tf.summary.merge([
            train_l2_loss_summary,train_penalty_summary,train_l2_loss_pslength_summary,train_l2_loss_pd_summary,train_l2_loss_ps_summary,train_l2_loss_normal_summary,train_l2_loss_p_summary
        ])
        val_summary = tf.summary.merge([
            val_l2_loss_summary,val_l2_loss_pd_summary,val_l2_loss_pslength_summary,val_l2_loss_ps_summary,val_l2_loss_normal_summary,val_l2_loss_p_summary
        ])
        check_summary = tf.summary.merge([
            check_pic_summary,pattern_summary#,check_pic_ff_summary
        ])
        self.end_points["train_summary"] = train_summary
        self.end_points["val_summary"] = val_summary
        self.end_points["check_summary"] = check_summary

        #[8.2] initializer
        init = tf.global_variables_initializer()
        self.end_points['init'] = init
        #[8.3] saver
        saver = tf.train.Saver()
        self.end_points['saver'] = saver
        config = tf.ConfigProto() 
        config.gpu_options.allow_growth = True 
        self.sess = tf.Session(config=config)
        
        writer = tf.summary.FileWriter(self.logPath, tf.get_default_graph())
        self.end_points['writer'] = writer
示例#5
0
    make_dir(log_measurments_dir)
    make_dir(img_root)

    pf = open(log_root + "ae_output_data.bin", "wb")
    counter = 0
    while True:
        tmpData, ifValid, num = myMine.gen_batch()
        if not ifValid:
            break
        result = myTamer.check_quality(tmpData)
        result[1][:num].astype(np.float32).tofile(pf)
        tmp_m = result[2].reshape(
            [-1, 3, train_configs["measurements_length"]])
        tmp_lumis = result[1][:num].reshape(
            [-1, 3, train_configs["lumitexel_length"]])
        num = tmp_m.shape[0]
        for idx in range(num):
            np.savetxt(log_measurments_dir + "{}_mm.csv".format(counter),
                       tmp_m[idx].T,
                       delimiter=',')
            img = []
            for lumi in tmp_lumis[idx]:
                img.append(visualize_new(lumi))
            img = np.array(img)
            img = np.transpose(img, axes=[1, 2, 0])
            img = img[:, :, ::-1]
            cv2.imwrite(img_root + "{}.png".format(counter), img * 255.0 * 0.5)
            counter += 1
        # break
    pf.close()
    print("[TAME]training done.")
示例#6
0
                if need_dump:
                    tmp_guessed_params, tmp_rendered = sess.run(
                        [guessed_params_node, rendered_lumi_node],
                        feed_dict={
                            input_measurements:
                            tmp_measurements,
                            input_positions:
                            np.zeros([test_configs["batch_size"], 3],
                                     np.float32)
                        })
                    tmp_guessed_params = tmp_guessed_params[:valids]
                    tmp_guessed_params.tofile(presf)
                    np.savetxt(f_test, tmp_guessed_params, delimiter=',')
                    tmp_rendered = tmp_rendered[:valids] * 5 * 1e3 / math.pi
                    for idx_tmp, a_lumi in enumerate(tmp_rendered):
                        img = visualize_new(a_lumi, scalerf=255.0)
                        cv2.imwrite(
                            log_root + "img_{}.png".format(data_ptr + idx_tmp),
                            img)

                else:
                    tmp_guessed_params = sess.run(
                        guessed_params_node,
                        feed_dict={
                            input_measurements:
                            tmp_measurements,
                            input_positions:
                            np.zeros([test_configs["batch_size"], 3],
                                     np.float32)
                        })
                    np.savetxt(f_test, tmp_guessed_params, delimiter=',')
import numpy as np
import cv2
import math
import sys
sys.path.append("../utils/")
from lumitexel_related import visualize_init, visualize_new

lumitexel_size = 24576
scaler = 5 * 1e3 / math.pi

UTILS_CONFIG_PATH = "G:/current_work/utils/"

if __name__ == "__main__":
    visualize_init(UTILS_CONFIG_PATH)
    thread_id = 1
    parameters = {}
    parameters["config_dir"] = "../tf_ggx_render/tf_ggx_render_configs_1x1/"

    root = "G:/no_where/test_rendering/"

    data = np.fromfile(root + "cpu_lumi.bin",
                       np.float32).reshape([-1, 2, lumitexel_size])
    data2 = np.fromfile(root + "tf_lumi.bin",
                        np.float32).reshape([-1, 2, lumitexel_size])
    for idx, a_lumi in enumerate(data):
        cv2.imshow("img_direct", visualize_new(a_lumi[0], scalerf=scaler))
        cv2.imshow("img_omega", visualize_new(a_lumi[1], scalerf=scaler))
        cv2.imshow("img2_direct", visualize_new(data2[idx][0], scalerf=1))
        cv2.imshow("img2_omega", visualize_new(data2[idx][1], scalerf=1))
        cv2.waitKey(0)
示例#8
0
import sys
sys.path.append("../")
from lumitexel_related import visualize_init, shrink, expand_img, visualize_new, get_visualize_idxs
import numpy as np
import cv2

lumitexel_size = 24576
block_size = 64
UITLS_PATH = "../"
if __name__ == "__main__":
    visualize_init(UITLS_PATH)
    idxes = get_visualize_idxs()  #[24576,2]

    origin_lumitexel = np.array(range(lumitexel_size), np.int32) + 1

    lumitexel_img = visualize_new(origin_lumitexel).astype(np.int32)

    itr_count = 0

    block_num = 64 // block_size

    idx_collector = []
    idx_invert_collector = np.zeros(lumitexel_size, np.int32)

    for x in range(block_num * 4):
        for y in range(block_num * 3):
            real_x = x * block_size
            real_y = y * block_size
            hit_point = (idxes[:, 0] == real_x) & (idxes[:, 1] == real_y)
            if np.count_nonzero(hit_point) != 0:
                for i in range(block_size):
示例#9
0
import numpy as np
import cv2
import sys
sys.path.append("../utils/")
from dir_folder_and_files import make_dir
from lumitexel_related import visualize_init,visualize_new

UTILS_CONFIG_PATH = "G:/current_work/utils/"

if __name__ == "__main__":
    data_root=sys.argv[1]
    data_name=sys.argv[2]

    visualize_init(UTILS_CONFIG_PATH)

    data = np.fromfile(data_root+data_name,np.float32).reshape([-1,3,24576])

    img_root = data_root+"img/"
    make_dir(img_root)
    for idx,apixel in enumerate(data):
        r = np.expand_dims(visualize_new(apixel[0]),axis=2)
        g = np.expand_dims(visualize_new(apixel[1]),axis=2)
        b = np.expand_dims(visualize_new(apixel[2]),axis=2)

        img = np.concatenate([b,g,r],axis=-1)
        cv2.imwrite(img_root+"{}.png".format(idx),img*255)