How to train images in CNN with Tensorflow
Date : March 29 2020, 07:55 AM
|
how do i make labels list manually for my imported images in tensorflow
Date : March 29 2020, 07:55 AM
wish help you to fix your issue , If you know you want labels = [1, 1, 1, 0, 0], just use tf.one_hot(labels, depth=2)
array([[ 0., 1.],
[ 0., 1.],
[ 0., 1.],
[ 1., 0.],
[ 1., 0.]], dtype=float32)
<tf.Tensor 'one_hot:0' shape=(5, 2) dtype=float32>
labels = tf.placeholder(tf.int32, [None]) # 'None' means it has one dimension that is determined by your batch size
# ... define your network ...
loss_op = tf.nn.softmax_cross_entropy_with_logits(logits=logits,
labels=tf.one_hot(labels))
loss_op = tf.reduce_mean(loss_op)
for _ in range(num_iter):
d = # generate data batch
t = # generate label batch, e.g. [1, 1] for the first two images
_, batch_loss = sess.run([train_op, loss_op],
feed_dict={data: d, labels: t})
|
Tensorflow: batching labels with tf.train.batch
Date : March 29 2020, 07:55 AM
|
Tensorflow - use string labels to train neural network
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Finally I've found the error. Because I'm quite new to machine learning I've forgot that many algorithms does not handle categorical datasets. The solution has been to perform a one-hot encoding on the target labels and feed this new array to the newtork with this function: # define universe of possible input values
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# define a mapping of chars to integers
char_to_int = dict((c, i) for i, c in enumerate(alphabet))
int_to_char = dict((i, c) for i, c in enumerate(alphabet))
def one_hot_encode(data_array):
integer_encoded = [char_to_int[char] for char in data_array]
# one hot encode
onehot_encoded = list()
for value in integer_encoded:
letter = [0 for _ in range(len(alphabet))]
letter[value] = 1
onehot_encoded.append(letter)
return onehot_encoded
|
Convert Tensorflow Dataset into 2 arrays containing images and labels
Tag : python , By : DarrenBeck
Date : March 29 2020, 07:55 AM
should help you out If I understand your question well, what you need now to do is to concatenate to a numpy array as you iterate through your dataset. Note that, during iteration, if you apply .numpy() operation, you automatically convert from tf.tensor to np.array. Therefore, the following options are available to you: a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
np.concatenate((a, b), axis=0)
array([[1, 2],
[3, 4],
[5, 6]])
|