我的模型是keras和tensorflow的组合,如下所示:
with tf.Session(config=config) as sess:
with tf.device("/device:GPU:0"):
raw_img_float = tf.placeholder(tf.float32, shape=(None,512,640,3)) #tf.divide(tf.cast(raw_img, tf.float32),tf.constant(255.0))
bbox_tensor = tf.stack([by1,bx1,by2,bx2],axis=1)
cropped_img = tf.image.crop_and_resize(image=raw_img_float, # (n, 512, 640, 3)
boxes=bbox_tensor,# (n,4)
box_ind=list(range(BATCH)),#[0,1], # (n)
crop_size=[int(NETWORK_INPUT_SIZE),int(NETWORK_INPUT_SIZE)])
crop_width = tf.cast(tf.subtract(bx2,bx1), tf.float32)
new_crop_width = tf.reshape(crop_width, [-1, 1])
crop_height = tf.cast(tf.subtract(by2,by1), tf.float32)
new_crop_height = tf.reshape(crop_height, [-1, 1])
x_coords = tf.placeholder(tf.float32, shape=(None,5))
y_coords = tf.placeholder(tf.float32, shape=(None,5))
with tf.device("/device:GPU:1"):
inception = InceptionV3(weights='imagenet', include_top=False,
input_shape=(299,299,3))
inception_transfer = inception(cropped_img)
inception_transfer_flatten = Flatten(name='flatten')(inception_transfer)
inception_do1 = Dropout(0.5)(inception_transfer_flatten)
inception_regress_x = Dense(5, name='inception_regress_x')(inception_do1)
inception_regress_y = Dense(5, name='inception_regress_y')(inception_do1)
saver = tf.train.Saver(var_list=tf.trainable_variables())
ckpt = tf.train.get_checkpoint_state('checkpoint1')
sess.run(tf.global_variables_initializer())
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
print('RESTORED')
....
if global_step.eval(session=sess) % 200 == 0:
model_path =
os.path.join(os.path.join(os.getcwd(),'checkpoint1'),'model.ckpt')
saver.save(sess, model_path, global_step=global_step)
我训练了上面的模型,看到成本下降得很顺利。在
但在对权重进行加载和执行时,却显示了完全没有经过训练的模型的结果。。。在
如何保存定义为kerasapi的模型的权重?在
提前谢谢。。。在
目前没有回答
相关问题 更多 >
编程相关推荐