Пример #1
0
    def setup_train8(self, lr):

        image_batch, annotation_batch = tf.train.shuffle_batch( [self.resized_image, self.resized_annotation],
                                                     batch_size=1,
                                                     capacity=3000,
                                                     num_threads=2,
                                                     min_after_dequeue=1000)


        upsampled_logits_batch, fcn_8s_variables_mapping = FCN_8s(image_batch_tensor=image_batch,
                                                                   number_of_classes=self.num_labels,
                                                                   is_training=True)

        valid_labels_batch_tensor, valid_logits_batch_tensor = get_valid_logits_and_labels(annotation_batch_tensor=annotation_batch,
                                                                                           logits_batch_tensor=upsampled_logits_batch,
                                                                                           class_labels=self.class_labels)


        # Count true positives, true negatives, false positives and false negatives.
        actual = tf.contrib.layers.flatten(tf.cast(annotation_batch, tf.int64))

        self.predicted_img = tf.argmax(upsampled_logits_batch, axis=3)
        cross_entropies = tf.nn.softmax_cross_entropy_with_logits(logits=valid_logits_batch_tensor,
                                                                  labels=valid_labels_batch_tensor)
        self.cross_entropy_sum = tf.reduce_mean(cross_entropies)

        pred = tf.argmax(upsampled_logits_batch, dimension=3)

        probabilities = tf.nn.softmax(upsampled_logits_batch)


        with tf.variable_scope("adam_vars"):
            self.train_step = tf.train.AdamOptimizer(learning_rate=lr).minimize(self.cross_entropy_sum)


        # Variable's initialization functions

        self.init_fn = slim.assign_from_checkpoint_fn(model_path=self.fcn_8s_checkpoint_path,
                                                 var_list=fcn_8s_variables_mapping)

        global_vars_init_op = tf.global_variables_initializer()

        self.merged_summary_op = tf.summary.merge_all()

        self.summary_string_writer = tf.summary.FileWriter("./log_8_{}".format(lr))

        if not os.path.exists(self.checkpointnew):
             os.makedirs(self.checkpointnew)
            
        #The op for initializing the variables.
        local_vars_init_op = tf.local_variables_initializer()

        self.combined_op = tf.group(local_vars_init_op, global_vars_init_op)

        # We need this to save only model variables and omit
        # optimization-related and other variables.
        model_variables = slim.get_model_variables()
        self.saver = tf.train.Saver(model_variables)
Пример #2
0
resized_annotation = tf.squeeze(resized_annotation)

image_batch, annotation_batch = tf.train.shuffle_batch( [resized_image, resized_annotation],
                                             batch_size=1,
                                             capacity=samples,
                                             num_threads=2,
                                                        min_after_dequeue=70)

upsampled_logits_batch, vgg_16_variables_mapping = FCN_32s(image_batch_tensor=image_batch,
                                                           number_of_classes=number_of_classes,
                                                           is_training=True)


valid_labels_batch_tensor, valid_logits_batch_tensor = get_valid_logits_and_labels(annotation_batch_tensor=annotation_batch,
                                                                                     logits_batch_tensor=upsampled_logits_batch,
                                                                                    class_labels=class_labels)



cross_entropies = tf.nn.softmax_cross_entropy_with_logits(logits=valid_logits_batch_tensor,
                                                          labels=valid_labels_batch_tensor)

# Normalize the cross entropy -- the number of elements
# is different during each step due to mask out regions
cross_entropy_sum = tf.reduce_mean(cross_entropies)

pred = tf.argmax(upsampled_logits_batch, dimension=3)

probabilities = tf.nn.softmax(upsampled_logits_batch)
Пример #3
0
    resized_annotation = tf.squeeze(resized_annotation)

    image_batch, annotation_batch = tf.train.shuffle_batch( [resized_image, resized_annotation],
                                                 batch_size=1,
                                                 capacity=3000,
                                                 num_threads=2,
                                                 min_after_dequeue=1000)

    upsampled_logits_batch, fcn_8s_variables_mapping = FCN_8s(image_batch_tensor=image_batch,
                                                               number_of_classes=number_of_classes,
                                                               is_training=True)


    valid_labels_batch_tensor, valid_logits_batch_tensor = get_valid_logits_and_labels(annotation_batch_tensor=annotation_batch,
                                                                                         logits_batch_tensor=upsampled_logits_batch,
                                                                                        class_labels=class_labels)

    actual = tf.contrib.layers.flatten(tf.cast(annotation_batch, tf.int64))

    predicted_img = tf.argmax(upsampled_logits_batch, axis=3)

    predicted = tf.contrib.layers.flatten(predicted_img)
    #actual = tf.reshape(actual2, [1, 50176])
    tp = tf.count_nonzero(predicted * actual)
    tn = tf.count_nonzero((predicted - 1) * (actual - 1))
    fp = tf.count_nonzero(predicted * (actual - 1))
    fn = tf.count_nonzero((predicted - 1) * actual)
        
    # Calculate accuracy, precision, recall and F1 score.
    accuracy = tf.divide(tf.add(tp, tn), tf.add(tf.add(tp, fp), tf.add(fn, tn)))
Пример #4
0
    def setup_train8(self, lr):
        """
        Setups queues and model evaluation.
        """

        image_batch, annotation_batch = tf.train.shuffle_batch(
            [self.resized_image, self.resized_annotation],
            batch_size=1,
            capacity=3000,
            num_threads=2,
            min_after_dequeue=1000)

        upsampled_logits_batch, fcn_8s_variables_mapping = FCN_8s(
            image_batch_tensor=image_batch,
            number_of_classes=self.num_labels,
            is_training=True)

        valid_labels_batch_tensor, valid_logits_batch_tensor = get_valid_logits_and_labels(
            annotation_batch_tensor=annotation_batch,
            logits_batch_tensor=upsampled_logits_batch,
            class_labels=self.class_labels)

        # Count true positives, true negatives, false positives and false negatives.
        actual = tf.contrib.layers.flatten(tf.cast(annotation_batch, tf.int64))

        self.predicted_img = tf.argmax(upsampled_logits_batch, axis=3)
        cross_entropies = tf.nn.softmax_cross_entropy_with_logits(
            logits=valid_logits_batch_tensor, labels=valid_labels_batch_tensor)
        self.cross_entropy_sum = tf.reduce_mean(cross_entropies)

        pred = tf.argmax(upsampled_logits_batch, dimension=3)

        probabilities = tf.nn.softmax(upsampled_logits_batch)

        with tf.variable_scope("adam_vars"):
            self.train_step = tf.train.AdamOptimizer(
                learning_rate=lr).minimize(self.cross_entropy_sum)

        # Variable's initialization functions

        self.init_fn = slim.assign_from_checkpoint_fn(
            model_path=self.fcn_8s_checkpoint_path,
            var_list=fcn_8s_variables_mapping)

        global_vars_init_op = tf.global_variables_initializer()

        self.merged_summary_op = tf.summary.merge_all()

        self.summary_string_writer = tf.summary.FileWriter(
            "./log_8_{}".format(lr))

        if not os.path.exists(self.checkpointnew):
            os.makedirs(self.checkpointnew)

        #The op for initializing the variables.
        local_vars_init_op = tf.local_variables_initializer()

        self.combined_op = tf.group(local_vars_init_op, global_vars_init_op)

        # We need this to save only model variables and omit
        # optimization-related and other variables.
        model_variables = slim.get_model_variables()
        self.saver = tf.train.Saver(model_variables)