Esempio n. 1
0
def show_recons_samples(sess, ckptfile):
  # visualize sample reconstructions
  e2c.saver.restore(sess, ckptfile) # restore variable values
  dataset=PlaneData("data/plane1.npz","data/env1.png")
  dataset.initialize()
  (x_val,u_val,x_next_val)=dataset.sample(e2c.batch_size)
  xr,xp=sess.run([e2c.x_recons, e2c.x_predict],feed_dict={e2c.x:x_val,e2c.u:u_val,e2c.x_next:x_next_val})
  #xr,xp=sess.run([e2c.x_recons0, e2c.x_predict0],feed_dict={e2c.x0:x_val,e2c.u0:u_val,e2c.x1:x_next_val})
  A,B=e2c.A,e2c.B
  def getimgs(x,xnext):
    padsize=1
    padval=.5
    ph=B+2*padsize
    pw=A+2*padsize
    img=np.ones((10*ph,2*pw))*padval
    for i in range(10):
      startr=i*ph+padsize
      img[startr:startr+B,padsize:padsize+A]=x[i,:].reshape((A,B))
    for i in range(10):
      startr=i*ph+padsize
      img[startr:startr+B,pw+padsize:pw+padsize+A]=xnext[i,:].reshape((A,B))
    return img
  fig,arr=plt.subplots(1,2)
  arr[0].matshow(getimgs(x_val,x_next_val),cmap=plt.cm.gray,vmin=0,vmax=1)
  arr[0].set_title('Data')
  arr[1].matshow(getimgs(xr,xp),cmap=plt.cm.gray,vmin=0,vmax=1)
  arr[1].set_title('Reconstruction')
  plt.show()
Esempio n. 2
0
    dataset = PlaneData("data/plane1.npz", "data/env1.png")
    dataset.initialize()

    # tmp
    # (x_val,u_val,x_next_val)=dataset.sample(batch_size, replace=False)
    # feed_dict={
    #   x:x_val,
    #   u:u_val,
    #   x_next:x_next_val
    # }
    # results=sess.run([L_x,L_x_next,L_z,L_bound,KL],feed_dict)
    # pdb.set_trace()
    # resume training
    #saver.restore(sess, "/ltmp/e2c-plane-83000.ckpt")
    train_iters = 2e5  # 5K iters
    for i in range(int(train_iters)):
        (x_val, u_val, x_next_val) = dataset.sample(batch_size, replace=False)
        feed_dict = {x: x_val, u: u_val, x_next: x_next_val}
        plt.hist(x_val[0, :])
        plt.show()
        results = sess.run([loss, all_summaries, train_op], feed_dict)
        if i % 1000 == 0:
            print("iter=%d : Loss: %f" % (i, results[0]))
            if i > 2000:
                writer.add_summary(results[1], i)
        if (i % 100 == 0 and i < 1000) or (i % 1000 == 0):
            saver.save(sess, ckpt_file + "-%05d" % (i) + ".ckpt")

    sess.close()
Esempio n. 3
0
  dataset.initialize()

  # tmp
  # (x_val,u_val,x_next_val)=dataset.sample(batch_size, replace=False)
  # feed_dict={
  #   x:x_val,
  #   u:u_val,
  #   x_next:x_next_val
  # }
  # results=sess.run([L_x,L_x_next,L_z,L_bound,KL],feed_dict)
  # pdb.set_trace()
  # resume training
  #saver.restore(sess, "/ltmp/e2c-plane-83000.ckpt")
  train_iters=2e5 # 5K iters
  for i in range(int(train_iters)):
    (x_val,u_val,x_next_val)=dataset.sample(batch_size, replace=False)
    feed_dict={
      x:x_val,
      u:u_val,
      x_next:x_next_val
    }
    plt.hist(x_val[0,:])
    plt.show()
    results=sess.run([loss,all_summaries,train_op],feed_dict)
    if i%1000==0:
      print("iter=%d : Loss: %f" % (i,results[0]))
      if i>2000:
        writer.add_summary(results[1], i)
    if (i%100==0 and i < 1000) or (i % 1000 == 0):
      saver.save(sess,ckpt_file+"-%05d"%(i)+".ckpt")