Reputation: 531
I am training a model with multiple inputs for 10-fold cross validation. I used a loop to train 10 times a model with 10 different inputs. First time with first input data the networks trains and finishes. I use
sess.close()
in the end to close previous session and to remove all previous data. But when second input is given in the 2nd iteration, the training stops and give me below error at:
x = tf.placeholder("float", shape=[None, D], name='Input_data')
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Input_data' with dtype float
[[Node: Input_data = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
[[Node: Evaluating_accuracy/Mean/_91 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_145_Evaluating_accuracy/Mean", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
How can I fix this. If it works for the first time, than why it doesn't work for the second time with new data. Despite that I close the previous session.
Upvotes: 0
Views: 127
Reputation: 2364
You are probably redefining your graph in between folds. You should be creating a new session without redefining the graph.
When you run the tf.placeholder command the first time you are storing a pointer to the placeholder node in the python variable x. When you run it the second time, you overwrite that pointer. Essentially, you have a memory leak. There are now two placeholder nodes. One of them is pointed to by x and the original one is leaked.
Upvotes: 1