从元文件恢复图并应用渐变:AttributeError:'NoneType'对象没有属性'pred'

时间:2017-09-25 23:23:54

标签: tensorflow

我尝试恢复预先训练的模型,并在图表中添加其他图层。一切顺利,直到我应用优化器或计算梯度到损失。我收到如下错误消息:

AttributeError: 'NoneType' object has no attribute 'pred'

有没有人对此错误有任何想法?这是我的代码:

saver = tf.train.import_meta_graph(conf.pretrained_resnet50_meta)
graph = tf.get_default_graph()    
is_training = graph.get_tensor_by_name("plcaholders/is_training:0")
images = graph.get_tensor_by_name("images:0")
net = graph.get_tensor_by_name("avg_pool:0")


with tf.Session() as sess:

    saver = tf.train.Saver(var_list)
    sess.run(tf.global_variables_initializer())   
    saver.restore(sess, conf.pretrained_resnet50_ckpt)

#******Customized operations***************


    with tf.variable_scope("aic_fc"):
        weight = tf.get_variable("weights",[2048, 80], tf.float32, initializer=initializer)
        bias = tf.get_variable("bias",[80], tf.float32, initializer=initializer)


    with tf.variable_scope('preprocess') as scope:
        mean = tf.constant([114.156, 121.907, 126.488], dtype=tf.float32, shape=[1, 1, 1, 3], name='img_mean')
        processed_img = conf.imgs-mean

    with tf.variable_scope("network"):
        logits = tf.nn.xw_plus_b(net, weight, bias, name="fc3")

    with tf.variable_scope("training"):
        loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels = conf.label, logits=logits, name="cross_entropy"), name="loss")
        train_op = tf.train.GradientDescentOptimizer(conf.learning_rate).minimize(loss)


    init_new_vars_op = tf.variables_initializer([weight, bias])
    sess.run(init_new_vars_op)

    train_batch = data_u.get_batch('validation', conf.validation_idx_list, 0)
    feed_dict = {images:train_batch[0],  conf.label:train_batch[1], conf.learning_rate:1e-4, conf.is_training:True, conf.dropout:0.5}
    netout, _ = sess.run([loss  ,train_op], feed_dict = feed_dict)

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。问题是由我从此repo tensorflow-resent下载的模型图元文件引起的。我不知道提供的检查点文件发生了什么,但是当我尝试其他检查点文件时,一切都运行良好。