if i == 26: break if k == 'conv1_1_W': sess.run(en_parameters[i].assign(np.concatenate([weights[k],np.zeros([3,3,1,64])],axis = 2))) else: sess.run(en_parameters[i].assign(weights[k])) print('finish loading vgg16 model') #load train data while epoch_num < max_epochs: print('epoch %d' % epoch_num) while batch_num < batchs_per_epoch: print('batch %d, loading batch data...' % batch_num) batch_index = sess.run(index_dequeue_op) batch_RGB_paths = paths_RGB[batch_index] batch_alpha_paths = paths_alpha[batch_index] batch_FG_paths = paths_FG[batch_index] batch_BG_paths = paths_BG[batch_index] print('finish loading path') batch_RGBs,batch_trimaps,batch_alphas,batch_FGs,batch_BGs = load_data(sess,batch_RGB_paths,batch_alpha_paths,batch_FG_paths,batch_BG_paths) # feed = {image_batch:batch_RGBs.eval(), GT_matte_batch:batch_alphas.eval(),GT_trimap:batch_trimaps, GTBG_batch:batch_BGs.eval(), GTFG_batch:batch_FGs.eval(),is_train:True} feed = {image_batch:batch_RGBs, GT_matte_batch:batch_alphas,GT_trimap:batch_trimaps, GTBG_batch:batch_BGs, GTFG_batch:batch_FGs,is_train:True} _,loss,summary_str,step,p_mattes = sess.run([train_op,total_loss,summary_op,global_step,pred_mattes],feed_dict = feed) misc.imsave('./predict/alpha.jpg',p_mattes[0,:,:,0]) summary_writer.add_summary(summary_str,global_step = step) print('loss is %f' %loss) batch_num += 1 epoch_num += 1
else: sess.run(en_parameters[i].assign(weights[k])) print('finish loading vgg16 model') else: print('Restoring pretrained model...') saver.restore(sess, tf.train.latest_checkpoint('./model')) sess.graph.finalize() while epoch_num < max_epochs: while batch_num < batchs_per_epoch: batch_index = sess.run(index_dequeue_op) batch_alpha_paths = paths_alpha[batch_index] batch_eps_paths = paths_eps[batch_index] batch_BG_paths = paths_BG[batch_index] batch_RGBs, batch_trimaps, batch_alphas, batch_BGs, batch_FGs, RGBs_with_mean = load_data( batch_alpha_paths, batch_eps_paths, batch_BG_paths) feed = { image_batch: batch_RGBs, GT_matte_batch: batch_alphas, GT_trimap: batch_trimaps, GTBG_batch: batch_BGs, GTFG_batch: batch_FGs, raw_RGBs: RGBs_with_mean, training: True } _, loss, summary_str, step = sess.run( [train_op, total_loss, summary_op, global_step], feed_dict=feed) print('epoch %d batch %d loss is %f' %
nummm = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ] fff = -1 while epoch_num < max_epochs: while batch_num < batchs_per_epoch: fff = fff + 1 batch_index = sess.run(index_dequeue_op) batch_alpha_paths = paths_alpha[batch_index] batch_eps_paths = paths_eps[batch_index] batch_BG_paths = paths_BG[batch_index] batch_dir_paths = paths_dir[batch_index] # batch_RGBs,batch_trimaps,batch_alphas,batch_BGs,batch_FGs,RGBs_with_mean = load_data(batch_alpha_paths,batch_eps_paths,batch_BG_paths) batch_Gradients, batch_masks, batch_alphas = load_data( batch_alpha_paths, batch_eps_paths, batch_dir_paths) # feed = {image_batch:batch_RGBs, GT_matte_batch:batch_alphas,GT_trimap:batch_trimaps, GTBG_batch:batch_BGs, GTFG_batch:batch_FGs,raw_RGBs:RGBs_with_mean,training:True} feed = { image_batch: batch_Gradients, GT_matte_batch: batch_alphas, GT_mask: batch_masks, training: True } _, loss, summary_str, step = sess.run( [train_op, total_loss, summary_op, global_step], feed_dict=feed) # trimap=b_trimap.eval(feed_dict=feed) mask_ = b_mask.eval(feed_dict=feed) alpha_ = pred_final.eval(feed_dict=feed)