checkpoints_dir = '/tensorflow-FCN-textNonText/checkpoints' number_of_classes = 38 slim = tf.contrib.slim checkpoint_path = os.path.join(checkpoints_dir, 'vgg_16.ckpt') from fcn_32s import FCN_32s, extract_vgg_16_mapping_without_fc8 '''--------------------------------------------------------------------------------------------------------------------- Process batch with FCN_32s ---------------------------------------------------------------------------------------------------------------------''' is_training = tf.placeholder(tf.bool) upsampled_logits_batch, vgg_16_variables_mapping = FCN_32s(image_batch_tensor=img_batch, number_of_classes=number_of_classes, is_training=is_training) '''--------------------------------------------------------------------------------------------------------------------- Give a range to logits ---------------------------------------------------------------------------------------------------------------------''' margin_logits = tf.constant(10.0) upsampled_logits_batch = tf.maximum(tf.minimum(upsampled_logits_batch, margin_logits), -margin_logits) '''--------------------------------------------------------------------------------------------------------------------- Mask the output of the network and compute loss ---------------------------------------------------------------------------------------------------------------------''' # The FCN_32s output is a multiplication of 32. So, it should be resized as the img_batch before computing loss upsampled_logits_batch_resized = tf.image.resize_images(upsampled_logits_batch, (720, 1280)) # upsampled_logits_batch_resized = upsampled_logits_batch
feed_dict_to_use = {image_filename_placeholder: image_filename} image_tensor = tf.read_file(image_filename_placeholder) image_tensor = tf.image.decode_jpeg(image_tensor, channels=3) # Fake batch for image and annotation by adding leading empty axis. image_batch_tensor = tf.expand_dims(image_tensor, axis=0) # Be careful: after adaptation, network returns final labels and not logits FCN_32s = adapt_network_for_any_size_input(FCN_32s, 32) upsampled_logit, fcn_16s_variables_mapping_train = FCN_32s( image_batch_tensor=image_batch_tensor, number_of_classes=number_of_classes, is_training=False, reuse=None) pred = tf.argmax(upsampled_logit, dimension=3) probabilities = tf.nn.softmax(upsampled_logit) initializer = tf.local_variables_initializer() saver = tf.train.Saver() cmap = plt.get_cmap('bwr') #sess=tf.Session() with tf.Session() as sess: