示例#1
0
 def get_code_mean(self, inputs):
     if self.is_denoising == 1:
         inputs = draw_util.add_noise(inputs)
     elif self.is_denoising == 2:
         inputs = draw_util.erase(inputs)
     return self.sess.run(self.code_mean,
                          feed_dict={
                              self.input_layer: inputs,
                              self.batch_size: [len(inputs)]
                          })
示例#2
0
 def get_output_layer(self, inputs, ignore_noise=False):
     if not ignore_noise:
         if self.is_denoising == 1:
             inputs = draw_util.add_noise(inputs)
         elif self.is_denoising == 2:
             inputs = draw_util.erase(inputs)
     return self.sess.run(self.output_layer,
                          feed_dict={
                              self.input_layer: inputs,
                              self.batch_size: [len(inputs)]
                          })
示例#3
0
 def get_code_variance(self, inputs):
     if self.is_denoising == 1:
         inputs = draw_util.add_noise(inputs)
     elif self.is_denoising == 2:
         inputs = draw_util.erase(inputs)
     code_log_sigma_sq = self.sess.run(self.code_log_sigma_sq,
                                       feed_dict={
                                           self.input_layer: inputs,
                                           self.batch_size: [len(inputs)]
                                       })
     return np.exp(code_log_sigma_sq)
示例#4
0
 def calc_kl_divergence(self, inputs):
     if len(inputs) == 40000:
         A = self.calc_kl_divergence(inputs[:20000])
         B = self.calc_kl_divergence(inputs[20000:])
         return (A + B) / 2.0
     if self.is_denoising == 1:
         inputs = draw_util.add_noise(inputs)
     elif self.is_denoising == 2:
         inputs = draw_util.erase(inputs)
     return self.sess.run(self.kl_divergence,
                          feed_dict={
                              self.input_layer: inputs,
                              self.batch_size: [len(inputs)]
                          })
示例#5
0
 def partial_fit(self, targets):
     assert (self.is_training)
     if not self.is_denoising:
         self.sess.run(self.train_op,
                       feed_dict={
                           self.input_layer: targets,
                           self.batch_size: [len(targets)]
                       })
     else:
         inputs = draw_util.add_noise(targets) if self.is_denoising == 1 else \
             draw_util.erase(targets)
         self.sess.run(self.train_op,
                       feed_dict={
                           self.input_layer: inputs,
                           self.target_layer: targets,
                           self.batch_size: [len(targets)]
                       })
示例#6
0
 def calc_cost(self, targets):
     if len(targets) == 40000:
         A = self.calc_cost(targets[:20000])
         B = self.calc_cost(targets[20000:])
         return (A + B) / 2.0
     if not self.is_denoising:
         return self.sess.run(self.cost,
                              feed_dict={
                                  self.input_layer: targets,
                                  self.batch_size: [len(targets)]
                              })
     else:
         inputs = draw_util.add_noise(targets) if self.is_denoising == 1 else \
             draw_util.erase(targets)
         return self.sess.run(self.cost,
                              feed_dict={
                                  self.input_layer: inputs,
                                  self.target_layer: targets,
                                  self.batch_size: [len(targets)]
                              })
示例#7
0
 def calc_reconstruction_accuracy(self, targets):
     inputs = targets if not self.is_denoising else (draw_util.add_noise(targets) if \
         self.is_denoising == 1 else draw_util.erase(targets))
     predicted_images = self.get_output_layer(inputs)
     return np.mean(
         np.sqrt(np.sum(np.square(predicted_images - targets), axis=1)))