예제 #1
0
 def generate_plots(self, input_data, input_labels=None):
     """
 Plot weights, reconstruction, and gradients
 Inputs:
   input_data: data object containing the current image batch
   input_labels: data object containing the current label batch
 """
     super(ICA, self).generate_plots(input_data, input_labels)
     feed_dict = self.get_feed_dict(input_data, input_labels)
     weights = tf.get_default_session().run(self.a, feed_dict)
     current_step = str(self.global_step.eval())
     #pf.plot_data_tiled(input_data.reshape((self.batch_size,
     #  np.int(np.sqrt(self.num_pixels)),
     #  np.int(np.sqrt(self.num_pixels)))),
     #  normalize=False, title="Images at step "+current_step,
     #  vmin=np.min(input_data), vmax=np.max(input_data),
     #  save_filename=(self.disp_dir+"images_"+current_step.zfill(5)+".pdf"))
     pf.plot_data_tiled(
         weights.reshape(self.num_neurons, int(np.sqrt(self.num_pixels)),
                         int(np.sqrt(self.num_pixels))),
         normalize=True,
         title="Dictionary at step " + current_step,
         vmin=-1.0,
         vmax=1.0,
         save_filename=(self.disp_dir + "a_v" + self.version + "-" +
                        current_step.zfill(5) + ".pdf"))
     pf.plot_activity_hist(
         self.z.eval(feed_dict),
         num_bins=1000,
         title="z Activity Histogram at step " + current_step,
         save_filename=(self.disp_dir + "z_hist_v" + self.version + "-" +
                        current_step.zfill(5) + ".pdf"))
     pf.plot_activity_hist(
         self.u.eval(feed_dict),
         num_bins=1000,
         title="u Activity Histogram at step " + current_step,
         save_filename=(self.disp_dir + "u_hist_v" + self.version + "-" +
                        current_step.zfill(5) + ".pdf"))
     pf.plot_bar(np.linalg.norm(weights, axis=1, keepdims=False),
                 num_xticks=5,
                 title="a l2 norm",
                 xlabel="Basis Index",
                 ylabel="L2 Norm",
                 save_filename=(self.disp_dir + "a_norm_v" + self.version +
                                "-" + current_step.zfill(5) + ".pdf"))
     for weight_grad_var in self.grads_and_vars[self.sched_idx]:
         grad = weight_grad_var[0][0].eval(feed_dict)
         shape = grad.shape
         name = weight_grad_var[0][1].name.split('/')[1].split(':')[
             0]  #np.split
         pf.plot_data_tiled(
             grad.reshape(self.num_neurons, int(np.sqrt(self.num_pixels)),
                          int(np.sqrt(self.num_pixels))),
             normalize=False,
             title="Gradient for " + name + " at step " + current_step,
             vmin=None,
             vmax=None,
             save_filename=(self.disp_dir + "d" + name + "_v" +
                            self.version + "_" + current_step.zfill(5) +
                            ".pdf"))
예제 #2
0
 def save_data(self, data, datatype):
     fig_title = "Activity triggered averages on " + datatype + " data"
     for layer_idx, layer in enumerate(data):
         ata_filename = (self.analysis_out_dir + "act_trig_avg_layer_" +
                         str(layer_idx) + "_" + datatype + "_v" +
                         self.version + self.file_ext)
         ata = layer.reshape(layer.shape[0], int(np.sqrt(layer.shape[1])),
                             int(np.sqrt(layer.shape[1])))
         pf.plot_data_tiled(ata,
                            normalize=True,
                            title=fig_title,
                            vmin=-1.0,
                            vmax=1.0,
                            save_filename=ata_filename)
예제 #3
0
 def generate_plots(self, input_data, input_labels=None):
   """
   Plot weights, reconstruction, and gradients
   Inputs: input_data and input_labels used for the session
   """
   super(MLP, self).generate_plots(input_data, input_labels)
   feed_dict = self.get_feed_dict(input_data, input_labels)
   current_step = str(self.global_step.eval())
   pf.plot_data_tiled(
     self.w2.eval().T.reshape(self.num_classes,
     int(np.sqrt(self.num_hidden)), int(np.sqrt(self.num_hidden))),
     normalize=True, title="Classification matrix at step number "+current_step,
     vmin=None, vmax=None, save_filename=(self.disp_dir+"w2_v"+self.version+"-"
     +current_step.zfill(5)+".pdf"))
   pf.plot_data_tiled(
     self.w1.eval().T.reshape(self.num_hidden,
     int(np.sqrt(self.num_pixels)), int(np.sqrt(self.num_pixels))),
     normalize=True, title="Dictionary at step "+current_step, vmin=None, vmax=None,
     save_filename=(self.disp_dir+"w1_v"+self.version+"-"+current_step.zfill(5)+".pdf"))
   for weight_grad_var in self.grads_and_vars[self.sched_idx]:
     grad = weight_grad_var[0][0].eval(feed_dict)
     shape = grad.shape
     name = weight_grad_var[0][1].name.split('/')[1].split(':')[0]#np.split
     if name == "w1":
       pf.plot_data_tiled(grad.T.reshape(self.num_hidden,
         int(np.sqrt(self.num_pixels)), int(np.sqrt(self.num_pixels))),
         normalize=True, title="Gradient for w1 at step "+current_step, vmin=None, vmax=None,
         save_filename=(self.disp_dir+"dw1_v"+self.version+"_"+current_step.zfill(5)+".pdf"))
     elif name == "w2":
       pf.plot_data_tiled(grad.T.reshape(self.num_classes,
         int(np.sqrt(self.num_hidden)), int(np.sqrt(self.num_hidden))),
         normalize=True, title="Gradient for w2 at step "+current_step, vmin=None, vmax=None,
         save_filename=(self.disp_dir+"dw2_v"+self.version+"_"+current_step.zfill(5)+".pdf"))
예제 #4
0
 def generate_plots(self, input_data, input_labels=None):
     """
 Plot weights, reconstruction, and gradients
 Inputs:
   input_data: data object containing the current image batch
   input_labels: data object containing the current label batch
 """
     feed_dict = self.get_feed_dict(input_data, input_labels)
     current_step = str(self.global_step.eval())
     recon = tf.get_default_session().run(self.x_, feed_dict)
     weights = tf.get_default_session().run(self.phi, feed_dict)
     pf.plot_data_tiled(
         weights.T.reshape(self.num_neurons, int(np.sqrt(self.num_pixels)),
                           int(np.sqrt(self.num_pixels))),
         normalize=False,
         title="Dictionary at step " + current_step,
         vmin=None,
         vmax=None,
         save_filename=(self.disp_dir + "phi_v" + self.version + "_" +
                        current_step.zfill(5) + ".png"))
     pf.plot_data_tiled(
         input_data.reshape(
             (self.batch_size, np.int(np.sqrt(self.num_pixels)),
              np.int(np.sqrt(self.num_pixels)))),
         normalize=False,
         title="Images at step " + current_step,
         vmin=None,
         vmax=None,
         save_filename=(self.disp_dir + "images_" + self.version + "-" +
                        current_step.zfill(5) + ".png"))
     pf.plot_data_tiled(
         recon.reshape((self.batch_size, np.int(np.sqrt(self.num_pixels)),
                        np.int(np.sqrt(self.num_pixels)))),
         normalize=False,
         title="Recons at step " + current_step,
         vmin=None,
         vmax=None,
         save_filename=(self.disp_dir + "recons_v" + self.version + "-" +
                        current_step.zfill(5) + ".png"))
     for weight_grad_var in self.grads_and_vars[self.sched_idx]:
         grad = weight_grad_var[0][0].eval(feed_dict)
         shape = grad.shape
         name = weight_grad_var[0][1].name.split('/')[1].split(':')[
             0]  #np.split
         pf.plot_data_tiled(
             grad.T.reshape(self.num_neurons, int(np.sqrt(self.num_pixels)),
                            int(np.sqrt(self.num_pixels))),
             normalize=True,
             title="Gradient for phi at step " + current_step,
             vmin=None,
             vmax=None,
             save_filename=(self.disp_dir + "dphi_v" + self.version + "_" +
                            current_step.zfill(5) + ".pdf"))
예제 #5
0
 def generate_plots(self, input_data, input_labels=None):
   """
   Plot weights, reconstruction, and gradients
   Inputs:
     input_data: data object containing the current image batch
     input_labels: data object containing the current label batch
   """
   super(CONV_LCA, self).generate_plots(input_data, input_labels)
   feed_dict = self.get_feed_dict(input_data, input_labels)
   current_step = str(self.global_step.eval())
   pf.plot_data_tiled(
     self.phi.eval(), normalize=True,
     title="Dictionary at step "+current_step, vmin=None, vmax=None,
     save_filename=(self.disp_dir+"phi_v"+self.version+"_"+current_step.zfill(5)+".pdf"))
   for weight_grad_var in self.grads_and_vars[self.sched_idx]:
     grad = weight_grad_var[0][0].eval(feed_dict)
     shape = grad.shape
     name = weight_grad_var[0][1].name.split('/')[1].split(':')[0]#np.split
     pf.plot_data_tiled(grad, normalize=True,
       title="Gradient for phi at step "+current_step, vmin=None, vmax=None,
       save_filename=(self.disp_dir+"dphi_v"+self.version+"_"+current_step.zfill(5)+".pdf"))
 def generate_plots(self, input_data, input_labels=None):
     """
 Plot weights, reconstruction, and gradients
 Inputs:
   input_data: data object containing the current image batch
   input_labels: data object containing the current label batch
 """
     super(density_learner, self).generate_plots(input_data, input_labels)
     feed_dict = self.get_feed_dict(input_data, input_labels)
     current_step = str(self.global_step.eval())
     #recon = tf.get_default_session().run(self.x_, feed_dict)
     #weights = tf.get_default_session().run(self.phi, feed_dict)
     b_weights = tf.get_default_session().run(self.b, feed_dict)
     v_vals = tf.get_default_session().run(self.v, feed_dict)
     #pf.plot_data_tiled(input_data.reshape((self.batch_size,
     #  np.int(np.sqrt(self.num_pixels)), np.int(np.sqrt(self.num_pixels)))),
     #  normalize=False, title="Images at step "+current_step, vmin=None, vmax=None,
     #  save_filename=(self.disp_dir+"images_"+self.version+"-"+current_step.zfill(5)+".pdf"))
     #pf.plot_data_tiled(weights.T.reshape(self.num_neurons,
     #  int(np.sqrt(self.num_pixels)), int(np.sqrt(self.num_pixels))),
     #  normalize=False, title="Dictionary at step "+current_step, vmin=None, vmax=None,
     #  save_filename=(self.disp_dir+"phi_v"+self.version+"_"+current_step.zfill(5)+".pdf"))
     pf.plot_data_tiled(
         b_weights.T.reshape(self.num_v, int(np.sqrt(self.num_neurons)),
                             int(np.sqrt(self.num_neurons))),
         normalize=True,
         title="Density weights at step " + current_step,
         vmin=None,
         vmax=None,
         save_filename=(self.disp_dir + "b_v" + self.version + "_" +
                        current_step.zfill(5) + ".pdf"))
     #pf.plot_bar(np.linalg.norm(weights, axis=1, keepdims=False), num_xticks=5,
     #  title="phi l2 norm", xlabel="Basis Index", ylabel="L2 Norm",
     #  save_filename=(self.disp_dir+"phi_norm_v"+self.version+"-"+current_step.zfill(5)+".pdf"))
     pf.plot_bar(np.linalg.norm(b_weights, axis=1, ord=1, keepdims=False),
                 num_xticks=5,
                 title="b l1 norm",
                 xlabel="Basis Index",
                 ylabel="L1 Norm",
                 save_filename=(self.disp_dir + "b_norm_v" + self.version +
                                "-" + current_step.zfill(5) + ".pdf"))
     pf.plot_activity_hist(
         v_vals,
         num_bins=1000,
         title="v Activity Histogram at step " + current_step,
         save_filename=(self.disp_dir + "v_hist_v" + self.version + "-" +
                        current_step.zfill(5) + ".pdf"))
     #pf.plot_data_tiled(recon.reshape((self.batch_size,
     #  np.int(np.sqrt(self.num_pixels)), np.int(np.sqrt(self.num_pixels)))),
     #  normalize=False, title="Recons at step "+current_step, vmin=None, vmax=None,
     #  save_filename=(self.disp_dir+"recons_v"+self.version+"-"+current_step.zfill(5)+".pdf"))
     for weight_grad_var in self.grads_and_vars[self.sched_idx]:
         grad = weight_grad_var[0][0].eval(feed_dict)
         shape = grad.shape
         name = weight_grad_var[0][1].name.split('/')[1].split(':')[
             0]  #np.split
         if name == "phi":
             pf.plot_data_tiled(
                 grad.T.reshape(self.num_neurons,
                                int(np.sqrt(self.num_pixels)),
                                int(np.sqrt(self.num_pixels))),
                 normalize=True,
                 title="Gradient for phi at step " + current_step,
                 vmin=None,
                 vmax=None,
                 save_filename=(self.disp_dir + "dphi_v" + self.version +
                                "_" + current_step.zfill(5) + ".pdf"))
         elif name == "b":
             pf.plot_data_tiled(
                 grad.T.reshape(self.num_v, int(np.sqrt(self.num_neurons)),
                                int(np.sqrt(self.num_neurons))),
                 normalize=True,
                 title="Gradient for b at step " + current_step,
                 vmin=None,
                 vmax=None,
                 save_filename=(self.disp_dir + "db_v" + self.version +
                                "_" + current_step.zfill(5) + ".pdf"))