def predict(): global w, h, offset, f def parser(serialized_example): fs = tf.parse_single_example(serialized_example, features={ "r": tf.FixedLenFeature([9], tf.float32), "t": tf.FixedLenFeature([3], tf.float32), }) fs["r"] = tf.reshape(fs["r"], [3, 3]) fs["t"] = tf.reshape(fs["t"], [3, 1]) return fs lod_in = tf.compat.v1.placeholder(tf.float32, shape=[], name='lod_in') rot = tf.compat.v1.placeholder(tf.float32, shape=[3, 3], name='rotation') tra = tf.compat.v1.placeholder(tf.float32, shape=[3, 1], name='translation') testset = tf.data.TFRecordDataset( ["datasets/" + FLAGS.dataset + "/" + FLAGS.input + ".test"]) testset = testset.map(parser).repeat().batch(1).make_one_shot_iterator() features = testset.get_next() bg = tf.compat.v1.get_variable("Net_bg", initializer=np.array([1, 1, 1], dtype=np.float32), trainable=True) bg = tf.sigmoid(bg) depth_init = np.random.uniform( -5, 0, [num_mpi, int(h / FLAGS.subscale), int(w / FLAGS.subscale), sub_sam]).astype(np.float32) mpi = np.zeros([num_mpi, h, w, 4], dtype=np.float32) mpi[0] = [1., 0., 0., .95] mpi[1] = [1., .5, 0., .95] mpi[2] = [1., 1., 0., .95] mpi[3] = [.5, 1., 0., .95] depth = tf.get_variable("Net_depth", initializer=depth_init, trainable=True) depth = tf.sigmoid(depth) #depth = tf.image.resize(depth, [h, w], align_corners=True) with tf.compat.v1.variable_scope("Net"): mpi = tf.compat.v1.get_variable("mpi", initializer=mpi, trainable=False) mpi = tf.sigmoid(mpi) #depth = gen_depth(mpi,False) depth = tf.image.resize(depth, [h, w], align_corners=True) img_out, shifts, sss = network(mpi, depth, bg, rot, tra, FLAGS.index % mpi_max, False) long = tf.concat(shifts, 1) with tf.compat.v1.variable_scope("post"): image_out = tf.clip_by_value(img_out, 0.0, 1.0) longs = tf.clip_by_value(long, 0.0, 1.0) config = ConfigProto() config.gpu_options.allow_growth = True #config = ConfigProto(device_count = {'GPU': 0}) sess = tf.compat.v1.Session(config=config) sess.run(tf.compat.v1.global_variables_initializer()) variables_to_restore = slim.get_variables_to_restore() saver = tf.train.Saver(variables_to_restore) #localpp = getLocalPath("/home2/suttisak",'./model/' + FLAGS.dataset +'/'+ FLAGS.input+str((FLAGS.index)%mpi_max)) localpp = './model/' + FLAGS.dataset + '/tem' + str( (FLAGS.index) % mpi_max) ckpt = tf.train.latest_checkpoint(localpp) saver.restore(sess, ckpt) if True: for i in range(0, 300, 1): try: out0 = cv2.imread("result/frame/" + FLAGS.dataset + "_%04d.png" % ((300 * (FLAGS.index % mpi_max) + i - 300) % (300 * mpi_max))) out0 = cv2.cvtColor(out0, cv2.COLOR_BGR2RGB) / 255.0 feed = sess.run(features) if (i % 50 == 0): print(i, ((300 * (FLAGS.index % mpi_max) + i - 300) % (300 * mpi_max))) out = sess.run(image_out, feed_dict={ rot: feed["r"][0], tra: feed["t"][0] }) ii = i / 300 out = np.clip(out * ii + out0 * (1 - ii), 0.0, 1.0) plt.imsave( "result/frame/" + FLAGS.dataset + "_%04d.png" % ((300 * (FLAGS.index % mpi_max) + i - 300) % (300 * mpi_max)), out) except: feed = sess.run(features) if (i % 50 == 0): print(i, ((300 * (FLAGS.index % mpi_max) + i - 300) % (300 * mpi_max))) out = sess.run(image_out, feed_dict={ rot: feed["r"][0], tra: feed["t"][0] }) plt.imsave( "result/frame/" + FLAGS.dataset + "_%04d.png" % ((300 * (FLAGS.index % mpi_max) + i - 300) % (300 * mpi_max)), out) if (not FLAGS.endvdo): for i in range(0, 300, 1): feed = sess.run(features) if (i % 50 == 0): print(i, (300 * (FLAGS.index % mpi_max) + i)) out = sess.run(image_out, feed_dict={ rot: feed["r"][0], tra: feed["t"][0] }) plt.imsave( "result/frame/" + FLAGS.dataset + "_%04d.png" % (300 * (FLAGS.index % mpi_max) + i), out) cmd = 'ffmpeg -y -i ' + 'result/frame/' + FLAGS.dataset + '_%04d.png -c:v libx264 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -pix_fmt yuv420p result/' + FLAGS.dataset + '_moving.mp4' print(cmd) os.system(cmd) if True: webpath = "webpath/" #"/var/www/html/orbiter/" if not os.path.exists(webpath + FLAGS.dataset): os.system("mkdir " + webpath + FLAGS.dataset) for ii in range(1): ref_rt = np.array(ref_r[FLAGS.index % mpi_max + ii:FLAGS.index % mpi_max + ii + 1]) ref_tt = np.array(ref_t[FLAGS.index % mpi_max + ii:FLAGS.index % mpi_max + ii + 1]) print(ref_rt.shape) ret, sublay = sess.run([mpi, sss], feed_dict={ features['r']: ref_rt, features['t']: ref_tt }) sublayers = [] mpis = [] sublayers_combined = [] print("sublay", sublay[0].shape, len(sublay)) for i in range(num_mpi): mpis.append(ret[i, :, :, :4]) ls = [] for j in range(sub_sam): ls.append(sublay[sub_sam * i + j]) ls = np.concatenate(ls, 0) #ls = np.expand_dims(ls,-1) ls = np.tile(ls, (1, 1, 3)) sublayers.append(ls) ls = np.reshape( ls, (sub_sam, sublay[0].shape[0], sublay[0].shape[1], 3)) ls = np.clip(np.sum(ls, 0), 0.0, 1.0) sublayers_combined.append(ls) #out = np.rot90(out,1) mpis = np.concatenate(mpis, 1) plt.imsave( webpath + FLAGS.dataset + "/mpi%02d.png" % (FLAGS.index % mpi_max + ii), mpis) #plt.imsave(webpath + FLAGS.dataset+ "/mpi_alpha"+str(ii)+".png", np.tile(mpis[:, :, 3:], (1, 1, 3))) sublayers = np.concatenate(sublayers, 1) sublayers = np.clip(sublayers, 0, 1) plt.imsave( webpath + FLAGS.dataset + "/sublayer%02d.png" % (FLAGS.index % mpi_max + ii), sublayers) #sublayers_combined = np.concatenate(sublayers_combined, 1) #plt.imsave(webpath + FLAGS.dataset+ "/sublayers_combined.png", sublayers_combined) plt.imsave(webpath + FLAGS.dataset + "/mpi.png", mpis) plt.imsave(webpath + FLAGS.dataset + "/mpi_alpha.png", np.tile(mpis[:, :, 3:], (1, 1, 3))) namelist = "[" for ii in range(FLAGS.index % mpi_max + 1): namelist += "\"%02d\"," % (ii) namelist += "]" print(namelist) with open( webpath + FLAGS.dataset + "/extrinsics%02d.txt" % (FLAGS.index % mpi_max), "w") as fo: for i in range(3): for j in range(3): fo.write(str(ref_r[FLAGS.index % mpi_max][i, j]) + " ") fo.write(" ".join( [str(x) for x in np.nditer(ref_t[(FLAGS.index % mpi_max)])]) + "\n") generateWebGL(webpath + FLAGS.dataset + "/index.html", w, h, getPlanes(FLAGS.index % mpi_max), namelist, sub_sam, f, px, py)
def predict(): global w, h, offset, f def parser(serialized_example): fs = tf.parse_single_example(serialized_example, features={ "r": tf.FixedLenFeature([9], tf.float32), "t": tf.FixedLenFeature([3], tf.float32), }) fs["r"] = tf.reshape(fs["r"], [3, 3]) fs["t"] = tf.reshape(fs["t"], [3, 1]) return fs lod_in = tf.compat.v1.placeholder(tf.float32, shape=[], name='lod_in') rot = tf.compat.v1.placeholder(tf.float32, shape=[3, 3], name='rotation') tra = tf.compat.v1.placeholder(tf.float32, shape=[3, 1], name='translation') testset = tf.data.TFRecordDataset( ["datasets/" + FLAGS.dataset + "/" + FLAGS.input + ".test"]) testset = testset.map(parser).repeat().batch(1).make_one_shot_iterator() features = testset.get_next() nh = h + offset * 2 nw = w + offset * 2 depth_init = np.random.uniform( -5, 0, [num_mpi, int(nh / FLAGS.subscale), int(nw / FLAGS.subscale), sub_sam]).astype(np.float32) int_noise = np.random.uniform( -1, -1, [num_mpi, int(nh / 2), int(nw / 2), 4]).astype(np.float32) mpi = np.zeros([num_mpi, nh, nw, 4], dtype=np.float32) mpi[0] = [1., 0., 0., .95] mpi[1] = [1., .5, 0., .95] mpi[2] = [1., 1., 0., .95] mpi[3] = [.5, 1., 0., .95] with tf.compat.v1.variable_scope("Net%d" % (FLAGS.index)): if is_gen_mpi: noise = tf.compat.v1.get_variable("noise", initializer=int_noise, trainable=False) mpic = gen_mpi(noise, lod_in, is_train=True) else: mpic = tf.compat.v1.get_variable("mpi_c", initializer=mpi[:, :, :, :3], trainable=False) mpia1 = tf.compat.v1.get_variable("mpi_a", initializer=mpi[:num_mpi - 1, :, :, 3:4], trainable=False) mpia2 = tf.compat.v1.get_variable("mpi_la", initializer=mpi[:1, :, :, 3:4] * 0 + 5, trainable=False) mpia = tf.concat([mpia1, mpia2], 0) mpi = tf.concat([mpic, mpia], -1) mpi = tf.sigmoid(mpi) if is_gen_depth: if FLAGS.sublayers < 1: depth = tf.get_variable("Net_depth", initializer=np.ones( (num_mpi, 3, 3, 1)), trainable=False) else: depth0 = gen_depth(mpi, True) else: depth1 = tf.get_variable("Net_depth", initializer=depth_init[:num_mpi - 1], trainable=True) depth2 = tf.get_variable( "depth2", initializer=depth_init[num_mpi - 1:, :, :, :sub_sam - 1], trainable=True) depth3 = tf.get_variable( "depth3", initializer=depth_init[num_mpi - 1:, :, :, :1] * 0 + 5, trainable=False) depth = tf.concat([depth2, depth3], -1) depth = tf.concat([depth1, depth], 0) #depth = tf.get_variable("Net_depth", initializer=depth_init, trainable=True) depth0 = tf.sigmoid(depth) depth = tf.image.resize(depth0, [nh, nw], align_corners=True) img_out, allalpha, mask = network(mpi, depth, rot, tra, False) with tf.compat.v1.variable_scope("post%d" % (FLAGS.index)): image_out = tf.clip_by_value(img_out, 0.0, 1.0) config = ConfigProto() config.gpu_options.allow_growth = True sess = tf.compat.v1.Session(config=config) sess.run(tf.compat.v1.global_variables_initializer()) variables_to_restore = slim.get_variables_to_restore() saver = tf.train.Saver(variables_to_restore) localpp = './model/' + FLAGS.dataset + "/s%02d" % FLAGS.subscale ckpt = tf.train.latest_checkpoint(localpp) saver.restore(sess, ckpt) if True: # make sample picture and video webpath = "webpath/" #"/var/www/html/orbiter/" if not os.path.exists(webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale): os.system("mkdir " + webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale) for i in range(0, 300, 1): feed = sess.run(features) out = sess.run(image_out, feed_dict={ lod_in: 0, rot: feed["r"][0], tra: feed["t"][0] }) if (i % 50 == 0): print(i) plt.imsave( "webpath/" + FLAGS.dataset + "_s%02d" % FLAGS.subscale + "/%04d.png" % (i), out) plt.imsave("result/frame/" + FLAGS.dataset + "_%04d.png" % (i), out) cmd = 'ffmpeg -y -i ' + 'result/frame/' + FLAGS.dataset + '_%04d.png -c:v libx264 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -pix_fmt yuv420p webpath/' + FLAGS.dataset + "_s%02d" % FLAGS.subscale + '/moving.mp4' print(cmd) os.system(cmd) if True: # make web viewer webpath = "webpath/" #"/var/www/html/orbiter/" if not os.path.exists(webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale): os.system("mkdir " + webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale) ret, sublay = sess.run([mpi, depth0], feed_dict={lod_in: 0}) sublayers = [] mpis = [] sublayers_combined = [] for i in range(num_mpi): mpis.append(ret[i, :, :, :4]) ls = [] for j in range(sub_sam): ls.append(sublay[i, :, :, j:j + 1]) ls = np.concatenate(ls, 0) ls = np.tile(ls, (1, 1, 3)) sublayers.append(ls) ls = np.reshape( ls, (sub_sam, sublay[0].shape[0], sublay[0].shape[1], 3)) ls = np.clip(np.sum(ls, 0), 0.0, 1.0) sublayers_combined.append(ls) mpis = np.concatenate(mpis, 1) plt.imsave( webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale + "/mpi%02d.png" % (FLAGS.index), mpis) sublayers = np.concatenate(sublayers, 1) sublayers = np.clip(sublayers, 0, 1) plt.imsave( webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale + "/sublayer%02d.png" % (FLAGS.index), sublayers) plt.imsave( webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale + "/mpi.png", mpis) plt.imsave( webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale + "/mpi_alpha.png", np.tile(mpis[:, :, 3:], (1, 1, 3))) namelist = "[" for ii in range(FLAGS.index + 1): namelist += "\"%02d\"," % (ii) namelist += "]" print(namelist) with open( webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale + "/extrinsics%02d.txt" % (FLAGS.index), "w") as fo: for i in range(3): for j in range(3): fo.write(str(ref_r[i, j]) + " ") fo.write(" ".join([str(x) for x in np.nditer(ref_t)]) + "\n") generateWebGL( webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale + "/index.html", w, h, getPlanes(), namelist, sub_sam, f, px, py) generateConfigGL( webpath + FLAGS.dataset + "_s%02d" % FLAGS.subscale + "/config.js", w, h, getPlanes(), namelist, sub_sam, f, px, py)
def predict(): global w, h, offset, f def parser(serialized_example): fs = tf.parse_single_example( serialized_example, features={ "r": tf.FixedLenFeature([9], tf.float32), "t": tf.FixedLenFeature([3], tf.float32), }) fs["r"] = tf.reshape(fs["r"], [3, 3]) fs["t"] = tf.reshape(fs["t"], [3, 1]) return fs lod_in = tf.placeholder(tf.float32, shape=[], name='lod_in') testset = tf.data.TFRecordDataset(["datasets/" + FLAGS.dataset + "/" + FLAGS.input + ".test"]) testset = testset.map(parser).repeat().batch(1).make_one_shot_iterator() features = testset.get_next() #features = {} #features["r"] = tf.convert_to_tensor(np.array([ref_r])) #features["t"] = tf.convert_to_tensor(np.array([ref_t])) #features = tf.convert_to_tensor(features) latent = np.zeros([laten_d, laten_h, laten_w, 1],dtype=np.float32) latent[-2:laten_d,:,:,0] = 0.5 for i in range(laten_d): ch, cw = int(laten_h/2-i/2), int(laten_w/2-i/4) latent[i,ch-10:ch+10,cw-5:cw+5,0] = 1.0 mpi = np.zeros([num_mpi*reuse_fac, size_h, size_w, 4],dtype=np.float32) mpi[0] = [1.,0.,0.,.95] mpi[1] = [1.,.5,0.,.95] mpi[2] = [1.,1.,0.,.95] mpi[3] = [.5,1.,0.,.95] mpi_c = np.random.uniform(-3,1,[num_mpi, size_h, size_w, 3]).astype(np.float32) mpi_a = np.random.uniform(-3,1,[num_mpi*reuse_fac, size_h, size_w, 1]).astype(np.float32) bg = tf.get_variable("bg", initializer=np.array([5,5,5],dtype=np.float32), trainable=True) bg = tf.sigmoid(bg) latent = tf.get_variable("depth", initializer=latent, trainable=False) latent = tf.sigmoid(latent) if (reuse_fac == 1): #mpi = tf.get_variable("mpi", initializer=mpi, trainable=True) mpi_c = tf.get_variable("mpic", initializer=mpi_c, trainable=True) mpi_a = tf.get_variable("mpia", initializer=mpi_a, trainable=True) #mpi_a = tf.round(mpi_a) #mpi_a = tf.where(tf.greater(mpi_a,0.5),5.*tf.ones_like(mpi_a),0.*tf.ones_like(mpi_a)) + tf.where(tf.greater(mpi_a,-1.5),0.*tf.ones_like(mpi_a),-5.*tf.ones_like(mpi_a)) mpi = tf.concat([mpi_c,mpi_a],-1) else: mpi_c = tf.get_variable("mpic", initializer=mpi_c, trainable=True) mpi_c = tf.tile(mpi_c, [2, 1, 1, 1]) mpi_a = tf.get_variable("mpia", initializer=mpi_a, trainable=True) mpi = tf.concat([mpi_c,mpi_a],-1) mpi = tf.sigmoid(mpi) img_out, shifts, sss = network(mpi, latent, bg, features, False) long = tf.concat(shifts, 1) img_out = tf.clip_by_value(img_out,0.0,1.0) long = tf.clip_by_value(long,0.0,1.0) config = ConfigProto() config.gpu_options.allow_growth = True #config = ConfigProto(device_count = {'GPU': 0}) sess = tf.Session(config=config) sess.run(tf.global_variables_initializer()) variables_to_restore = slim.get_variables_to_restore() saver = tf.train.Saver(variables_to_restore) ckpt = tf.train.latest_checkpoint('./model/' + FLAGS.dataset +'/'+ FLAGS.input ) saver.restore(sess, ckpt) if False: #bug = sess.run(long) #print(bug.shape) #out, bug = sess.run([img_out,latent]) #print(bug.shape) #plt.imshow(bug[:,:,:3]) #tt = np.concatenate([bug[1,:,:,0],bug[20,:,:,0],bug[40,:,:,0],bug[59,:,:,0]],1) #plt.matshow(tt,cmap='gray') #plt.imshow(out) #plt.show() print("!!") else: #ff = sess.run(features) #print(fff) if os.path.exists("result/frame"): os.system("rm -rf result/frame") os.makedirs("result/frame") for i in range(200): print(i) out = sess.run(img_out) #out, bug = sess.run([img_out,long]) #out = np.rot90(out,1) #plt.imsave("result/%04d.png"%(i),bug[:,:,:3]) plt.imsave("result/frame/%04d.png"%(i),out) cmd = 'ffmpeg -y -i ' + 'result/frame/\%04d.png -c:v libx264 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -pix_fmt yuv420p result/' +FLAGS.input+FLAGS.version+ '.mp4' print(cmd) os.system(cmd) if True: webpath = "/var/www/html/orbiter/" if not os.path.exists(webpath + FLAGS.input+FLAGS.version): os.system("mkdir " + webpath + FLAGS.input+FLAGS.version) ret, sublay = sess.run([mpi,sss],feed_dict={features['r']:np.array([ref_r]),features['t']:np.array([ref_t])}) sublayers = [] mpis = [] sublayers_combined = [] print("sublay",sublay[0].shape,len(sublay)) for i in range(num_mpi*reuse_fac): mpis.append(ret[i,:,:,:4]) ls = [] for j in range(sub_sam): ls.append(sublay[sub_sam*i+j]) ls = np.concatenate(ls,0) #ls = np.expand_dims(ls,-1) ls = np.tile(ls,(1,1,3)) sublayers.append(ls) ls = np.reshape(ls, (sub_sam,sublay[0].shape[0],sublay[0].shape[1],3)) ls = np.clip(np.sum(ls, 0), 0.0, 1.0) sublayers_combined.append(ls) #out = np.rot90(out,1) mpis = np.concatenate(mpis, 1) plt.imsave(webpath + FLAGS.input+FLAGS.version + "/mpi.png", mpis) plt.imsave(webpath + FLAGS.input+FLAGS.version + "/mpi_alpha.png", np.tile(mpis[:, :, 3:], (1, 1, 3))) sublayers = np.concatenate(sublayers, 1) sublayers = np.clip(sublayers, 0, 1) plt.imsave(webpath + FLAGS.input+FLAGS.version + "/sublayer.png", sublayers) sublayers_combined = np.concatenate(sublayers_combined, 1) plt.imsave(webpath + FLAGS.input+FLAGS.version + "/sublayers_combined.png", sublayers_combined) with open(webpath + FLAGS.input+FLAGS.version + "/extrinsics.txt", "w") as fo: for i in range(3): for j in range(3): fo.write(str(ref_r[i, j]) + " ") fo.write(" ".join([str(x) for x in np.nditer(ref_t)]) + "\n") generateWebGL(webpath + FLAGS.input+FLAGS.version + "/index.html", w, h, getPlanes(),sub_sam, f, px, py)
def predict(): global w, h, offset, f def parser(serialized_example): fs = tf.parse_single_example(serialized_example, features={ "r": tf.FixedLenFeature([9], tf.float32), "t": tf.FixedLenFeature([3], tf.float32), }) fs["r"] = tf.reshape(fs["r"], [3, 3]) fs["t"] = tf.reshape(fs["t"], [3, 1]) return fs lod_in = tf.placeholder(tf.float32, shape=[], name='lod_in') rot = tf.placeholder(tf.float32, shape=[3, 3], name='rotation') tra = tf.placeholder(tf.float32, shape=[3, 1], name='translation') testset = tf.data.TFRecordDataset([ "datasets/" + FLAGS.dataset + "/tem" + str(FLAGS.index % mpi_max) + ".test" ]) testset = testset.map(parser).repeat().batch(1).make_one_shot_iterator() features = testset.get_next() bg = tf.get_variable("Net_bg", initializer=np.array([1, 1, 1], dtype=np.float32), trainable=True) bg = tf.sigmoid(bg) latent = np.zeros([laten_d, laten_h, laten_w, 1], dtype=np.float32) latent[-2:laten_d, :, :, 0] = 0.5 for i in range(laten_d): ch, cw = int(laten_h / 2 - i / 2), int(laten_w / 2 - i / 4) latent[i, ch - 10:ch + 10, cw - 5:cw + 5, 0] = 1.0 mpi = np.zeros([num_mpi, h, w, 4], dtype=np.float32) mpi[0] = [1., 0., 0., .95] mpi[1] = [1., .5, 0., .95] mpi[2] = [1., 1., 0., .95] mpi[3] = [.5, 1., 0., .95] latent = tf.get_variable("Net_depth", initializer=latent, trainable=False) latent = tf.sigmoid(latent) mpis = [] image_out = [] longs = [] ssss = [] for i in range(num_): with tf.compat.v1.variable_scope("Net%d" % ((FLAGS.index + i) % mpi_max)): mpi = tf.get_variable("mpi", initializer=mpi, trainable=True) mpi = tf.sigmoid(mpi) mpis.append(mpi) img_out, shifts, sss = network(mpis[i], latent, bg, rot, tra, (FLAGS.index + i) % mpi_max, False) ssss.append(sss) long = tf.concat(shifts, 1) with tf.compat.v1.variable_scope("post%d" % ((FLAGS.index + i) % mpi_max)): image_out.append(tf.clip_by_value(img_out, 0.0, 1.0)) longs.append(tf.clip_by_value(long, 0.0, 1.0)) config = ConfigProto() config.gpu_options.allow_growth = True #config = ConfigProto(device_count = {'GPU': 0}) sess = tf.Session(config=config) sess.run(tf.global_variables_initializer()) variables_to_restore = slim.get_variables_to_restore() saver = tf.train.Saver(variables_to_restore) #localpp = getLocalPath("/home2/suttisak",'./model/' + FLAGS.dataset +'/'+ FLAGS.input+str((FLAGS.index)%mpi_max)) localpp = './model/' + FLAGS.dataset + '/' + FLAGS.input + str( (FLAGS.index) % mpi_max) ckpt = tf.train.latest_checkpoint(localpp) saver.restore(sess, ckpt) if FLAGS.FromFuture: t_vars = slim.get_variables_to_restore() vars_to_restore = [ var for var in t_vars if 'Net%d' % ((FLAGS.index + 1) % mpi_max) in var.name and 'Adam' not in var.name ] #print(vars_to_restore) saver = tf.train.Saver(vars_to_restore) #localpp0 = getLocalPath("/home2/suttisak",'./model/' + FLAGS.dataset +'/'+ FLAGS.input+str((FLAGS.index+1)%mpi_max)) localpp0 = './model/' + FLAGS.dataset + '/' + FLAGS.input + str( (FLAGS.index + 1) % mpi_max) ckpt = tf.train.latest_checkpoint(localpp0) saver.restore(sess, ckpt) if False: a = 0 #out, bug = sess.run([img_out,latent]) #tt = np.concatenate([bug[1,:,:,0],bug[20,:,:,0],bug[40,:,:,0],bug[59,:,:,0]],1) #plt.matshow(tt,cmap='gray') #plt.show() else: for i in range(0, 300, 1): feed = sess.run(features) if (i % 50 == 0): print(i) #out0, out1 = sess.run([image_out[0],image_out[1]]) out0 = sess.run(image_out[0], feed_dict={ rot: feed["r"][0], tra: feed["t"][0] }) out1 = sess.run(image_out[1], feed_dict={ rot: feed["r"][0], tra: feed["t"][0] }) #out, bug = sess.run([img_out,long]) #out0 = np.rot90(out0) #out1 = np.rot90(out1) out = (1 - i / 300) * out0 + ( i / 300) * out1 #np.concatenate((out0,out1),1) #plt.imsave("result/%04d.png"%(i),bug[:,:,:3]) plt.imsave( "result/frame/" + FLAGS.dataset + "_%04d.png" % (300 * (FLAGS.index % mpi_max) + i), out) cmd = 'ffmpeg -y -i ' + 'result/frame/' + FLAGS.dataset + '_%04d.png -c:v libx264 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -pix_fmt yuv420p result/' + FLAGS.dataset + '_moving.mp4' print(cmd) os.system(cmd) if False: #webpath = "/var/www/html/orbiter/" webpath = "webpath/" if not os.path.exists(webpath + FLAGS.dataset): os.system("mkdir " + webpath + FLAGS.dataset) for ii in range(1): ref_rt = np.array(ref_r[FLAGS.index + ii:FLAGS.index + ii + 1]) ref_tt = np.array(ref_t[FLAGS.index + ii:FLAGS.index + ii + 1]) print(ref_rt.shape) ret, sublay = sess.run([mpis[ii], ssss[ii]], feed_dict={ features['r']: ref_rt, features['t']: ref_tt }) sublayers = [] mpis = [] sublayers_combined = [] print("sublay", sublay[0].shape, len(sublay)) for i in range(num_mpi): mpis.append(ret[i, :, :, :4]) ls = [] for j in range(sub_sam): ls.append(sublay[sub_sam * i + j]) ls = np.concatenate(ls, 0) #ls = np.expand_dims(ls,-1) ls = np.tile(ls, (1, 1, 3)) sublayers.append(ls) ls = np.reshape( ls, (sub_sam, sublay[0].shape[0], sublay[0].shape[1], 3)) ls = np.clip(np.sum(ls, 0), 0.0, 1.0) sublayers_combined.append(ls) #out = np.rot90(out,1) mpis = np.concatenate(mpis, 1) plt.imsave( webpath + FLAGS.dataset + "/mpi%02d.png" % (FLAGS.index + ii), mpis) #plt.imsave(webpath + FLAGS.dataset+ "/mpi_alpha"+str(ii)+".png", np.tile(mpis[:, :, 3:], (1, 1, 3))) sublayers = np.concatenate(sublayers, 1) sublayers = np.clip(sublayers, 0, 1) plt.imsave( webpath + FLAGS.dataset + "/sublayer%02d.png" % (FLAGS.index + ii), sublayers) #sublayers_combined = np.concatenate(sublayers_combined, 1) #plt.imsave(webpath + FLAGS.dataset+ "/sublayers_combined.png", sublayers_combined) plt.imsave(webpath + FLAGS.dataset + "/mpi.png", mpis) plt.imsave(webpath + FLAGS.dataset + "/mpi_alpha.png", np.tile(mpis[:, :, 3:], (1, 1, 3))) namelist = "[" for ii in range(FLAGS.index + 1): namelist += "\"%02d\"," % (ii) namelist += "]" print(namelist) with open( webpath + FLAGS.dataset + "/extrinsics%02d.txt" % (FLAGS.index), "w") as fo: for i in range(3): for j in range(3): fo.write(str(ref_r[FLAGS.index][i, j]) + " ") fo.write( " ".join([str(x) for x in np.nditer(ref_t[(FLAGS.index)])]) + "\n") generateWebGL(webpath + FLAGS.dataset + "/index.html", w, h, getPlanes(), namelist, sub_sam, f, px, py)