简体   繁体   English

具有不同数据的Tensorflow重训练神经网络

[英]Tensorflow retrain neural network with different data

I have a list of inputs to the neural network for example 例如,我有神经网络的inputs列表

list_of_inputs = [inputs1, inputs2, inputs3, ... ,inputsN]

*and also a corresponding list of labels * *以及相应的标签列表*

list_of_labels = [label1, label2, label3, ..., labelN]

I want to feed/train each pair of input,label into the neural network, record the loss and then train the next pair of input,label on the same network and record the loss, etc. for all the input,label pairs. 我想将每对input,label /训练到神经网络中,记录损失,然后在同一网络上训练下一对input,label ,并记录所有input,label对的损失等。

Note: I don't want to reinitialize the weights every time a new input,label is added, I want to use the trained weights from the previous pair. 注意:我不想每次添加新的input,label都重新初始化权重,我想使用前一对中训练后的权重。 The network is shown below ( where you can see I am also printing the loss). 网络如下所示(您可以在此处看到我也在打印损失)。 How would I go about this? 我将如何处理?

with tf.name_scope("nn"):
    model = tf.keras.Sequential([
        tfp.layers.DenseFlipout(64, activation=tf.nn.relu),
        tfp.layers.DenseFlipout(64, activation=tf.nn.softmax),
        tfp.layers.DenseFlipout(np.squeeze(labels).shape[0])
    ])

logits = model(inputs)
loss = tf.reduce_mean(tf.square(labels - logits))
train_op_bnn = tf.train.AdamOptimizer().minimize(loss)


init_op = tf.group(tf.global_variables_initializer(),tf.local_variables_initializer())

with tf.Session() as sess:
    sess.run(init_op)
    for i in range(100):   
        sess.run(train_op_bnn)
        print(sess.run(loss))

EDIT: 编辑:

The issue is that when I try to format the network in a function as below: 问题是,当我尝试使用以下功能格式化网络时:

init_op = tf.group(tf.global_variables_initializer(),tf.local_variables_initializer())

with tf.Session() as sess:
    sess.run(init_op)

    inputs,labels = MEMORY[0]

    logits, model_losses = build_graph(inputs)
    loss = tf.reduce_mean(tf.square(labels - logits))
    train_op_bnn = tf.train.AdamOptimizer().minimize(loss)

    sess.run(train_op_bnn)
    print(sess.run(loss))   

I get an error: 我收到一个错误:

FailedPreconditionError                   Traceback (most recent call last)
<ipython-input-95-5ca77fa0606a> in <module>()
     36     train_op_bnn = tf.train.AdamOptimizer().minimize(loss)
     37 
---> 38     sess.run(train_op_bnn)
     39     print(sess.run(loss))
     40 
logits, model_losses = build_graph(inputs)
loss = tf.reduce_mean(tf.square(labels - logits))
train_op_bnn = tf.train.AdamOptimizer().minimize(loss)

should be above 应该在上面

with tf.Session() as sess:

and above your init_op definition 在您的init_op定义之上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重新训练 facenet 神经网络 - Retrain facenet neural network 经过训练的神经网络使用相同的数据产生不同的预测(TensorFlow) - Trained neural network produces different predictions with same data (TensorFlow) 将不同大小的输入数据馈入神经网络的好方法? (Tensorflow) - Good way to feed input data of different sizes into neural network? (Tensorflow) 是否可以使用`sklearn`重新训练保存的神经网络 - Is it possible to retrain a saved Neural Network using `sklearn` 添加到数据集后重新训练pybrain神经网络 - Retrain a pybrain neural network after adding to the dataset 具有不同尺寸图像的张量流卷积神经网络 - Tensorflow Convolution Neural Network with different sized images 张量流/keras 神经网络中的过度拟合和数据泄漏 - Overfitting and data leakage in tensorflow/keras neural network 在Tensorflow中,相同的训练数据和测试数据会导致神经网络的输出值不同 - Output values of neural network become different with same training data and test data in Tensorflow Tensorflow神经网络在创建服务器后会针对同一数据预测不同的答案 - Tensorflow neural network predicts different answers for the same data after creating a server 张量流神经网络尝试 - tensorflow neural network attempt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM