-
Notifications
You must be signed in to change notification settings - Fork 45.4k
Closed
Description
Hello,
I'm new in tensorflow.
I'm trying the resnet_v2_101 but i get an exception and i can't solve it.
My images are 488x488x3 my batchs size and num classes are 2.
So, this is my code:
num_classes = 2
net_input = tf.placeholder(tf.float32,shape=[None,None,None,3])
net_output = tf.placeholder(tf.float32,shape=[None,None,None,num_classes])
#build network
network,_ = resnet_v2.resnet_v2_101(tf.zeros([2,488,488,3]),num_classes , is_training=True, scope='resnet_v2_101')
sess.run(tf.global_variables_initializer())
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=network, labels=net_output))
opt = tf.train.RMSPropOptimizer(learning_rate=0.0001, decay=0.995).minimize(loss, var_list=[var for var in tf.trainable_variables()])
saver=tf.train.Saver(max_to_keep=1000)
sess.run(tf.global_variables_initializer())
# Do the training here
for epoch in range(args.epoch_start_i, args.num_epochs):
current_losses = []
# Equivalent to shuffling
id_list = np.random.permutation( len(train_input_names) )
num_iters = int(np.floor(len(id_list) / args.batch_size))
#for i in range(num_iters):
description_train = '[i]Train Epoch {:>2}/{}'.format(epoch + 1, args.num_epochs)
for i in tqdm(range(num_iters), desc=description_train, unit='batch'):
input_image_batch = []
output_image_batch = []
# Collect a batch of images
for j in range(args.batch_size):
index = i*args.batch_size + j
id = id_list[index]
input_image = utils.load_image(train_input_names[id])
output_image = utils.load_image(train_output_names[id])
with tf.device('/cpu:0'):
input_image, output_image = data_augmentation(input_image, output_image)
# Prep the data. Make sure the labels are in one-hot format
input_image = np.float32(input_image) / 255.0
output_image = np.float32(helpers.one_hot_it(label=output_image, label_values=label_values))
input_image_batch.append(np.expand_dims(input_image, axis=0))
output_image_batch.append(np.expand_dims(output_image, axis=0))
input_image_batch = np.squeeze(np.stack(input_image_batch, axis=1))
output_image_batch = np.squeeze(np.stack(output_image_batch, axis=1))
# Do the training
_,current=sess.run([opt,loss],feed_dict={net_input:input_image_batch,net_output:output_image_batch})
I get this traceback:
InvalidArgumentError (see above for traceback): logits and labels must be broadcastable: logits_size=[512,2048] labels_size=[100352,2]
How can i solve it?
System information
- What is the top-level directory of the model you are using: https://github.com/tensorflow/models/blob/master/research/slim/nets/resnet_v2.py
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- TensorFlow installed from (source or binary): pip install tensorflow-gpu
- TensorFlow version (use command below): 1.10.0
- Bazel version (if compiling from source): /
- CUDA/cuDNN version: 9.0
- GPU model and memory: NVIDIA Tesla V100
- Exact command to reproduce:
Metadata
Metadata
Assignees
Labels
No labels