Skip to content Skip to sidebar Skip to footer

Input A Csv File Into Tensorflow To Construct Neural Network

The following is my input format of CVS file Feature1, Feature2, ... Feature5, Label Feature1, Feature2, ... Feature5, Label According the tutorial on the Internet, I modified th

Solution 1:

You cannot feed tensors into placeholder variables. You have two options:

  1. Change the shape of the tensor y variable to accept labels. Then call tf.one_hot on that tensor:

    y = tf.placeholder(tf.int32, [None])
    y_one_hot = tf.one_hot(y, 2)
    ...
    # batch_labels is a list of integer labels
    _, c = sess.run([optimizer, cost], feed_dict={x: batch_x, y: batch_labels})
    
  2. Keep the tensor y as is and get the one hot feed values using a different class (numpy array in this example):

    # batch_labels is a list of integer labels
    batch_labels_one_hot = np.zeros((batch_size,2))
    batch_labels_one_hot[list(range(batch_size)), batch_labels]=1
    _,c= sess.run([optimizer, cost], feed_dict={x: batch_x, y: batch_labels_one_hot})

Post a Comment for "Input A Csv File Into Tensorflow To Construct Neural Network"