Beispiel #1
0
    def preprocess(self, image, gt_boxes):
        image, gt_boxes = utils.resize_image_correct_bbox(image, gt_boxes, self.image_h, self.image_w)

        if self.debug: return image, gt_boxes

        y_true_13, y_true_26, y_true_52 = tf.py_func(self.preprocess_true_boxes, inp=[gt_boxes],
                                                     Tout=[tf.float32, tf.float32, tf.float32])
        image = image / 255.
        # image , cellxcellx3x(4+1+class_id)
        return image, y_true_13, y_true_26, y_true_52
Beispiel #2
0
    def preprocess(self, image, gt_boxes):
        image, gt_boxes = utils.resize_image_correct_bbox(
            image, gt_boxes, self.IMAGE_H, self.IMAGE_W)
        if self.DEBUG: return image, gt_boxes
        # data augmentation (continue to work)

        image = image / 255.
        y_true, true_boxes = tf.py_func(self.preprocess_true_boxes,
                                        inp=[gt_boxes],
                                        Tout=[tf.float32, tf.float32])
        return image, y_true, true_boxes
Beispiel #3
0
    def preprocess(self, image, gt_boxes):

        image, gt_boxes = utils.resize_image_correct_bbox(
            image, gt_boxes, self.image_h, self.image_w)

        if self.debug:
            return image, gt_boxes

        y_true = tf.py_func(self.preprocess_true_boxes,
                            inp=[gt_boxes],
                            Tout=[tf.float32])

        return image, y_true
Beispiel #4
0
    def preprocess(self, image, gt_boxes):
        # resize_image_correct_bbox
        image, gt_boxes = utils.resize_image_correct_bbox(
            image, gt_boxes, self.image_h, self.image_w)
        if self.debug: return image, gt_boxes

        y_true_13, y_true_26, y_true_52 = tf.py_func(
            self.preprocess_true_boxes,
            inp=[gt_boxes],
            Tout=[tf.float32, tf.float32, tf.float32])
        # data augmentation
        # pass
        image = image / 255.

        return image, y_true_13, y_true_26, y_true_52
Beispiel #5
0
    def preprocess(self, image, gt_boxes):

        ################################# data augmentation ##################################
        # data_aug_flag = tf.to_int32(tf.random_uniform(shape=[], minval=-5, maxval=5))

        # caseO = tf.equal(data_aug_flag, 1), lambda: self.flip_left_right(image, gt_boxes)
        # case1 = tf.equal(data_aug_flag, 2), lambda: self.random_distort_color(image, gt_boxes)
        # case2 = tf.equal(data_aug_flag, 3), lambda: self.random_blur(image, gt_boxes)
        # case3 = tf.equal(data_aug_flag, 4), lambda: self.random_crop(image, gt_boxes)

        # image, gt_boxes = tf.case([caseO, case1, case2, case3], lambda: (image, gt_boxes))

        image, gt_boxes = utils.resize_image_correct_bbox(image, gt_boxes, self.image_h, self.image_w)

        if self.debug: return image, gt_boxes

        y_true_13, y_true_26, y_true_52 = tf.py_func(self.preprocess_true_boxes, inp=[gt_boxes],
                            Tout = [tf.float32, tf.float32, tf.float32])
        image = image / 255.

        return image, y_true_13, y_true_26, y_true_52
Beispiel #6
0
    def preprocess(self, image, gt_boxes):

        ################################# data augmentation ##################################
        is_flip = tf.random_uniform(shape=[],
                                    minval=0,
                                    maxval=2,
                                    dtype=tf.int32)
        is_distort = tf.random_uniform(shape=[],
                                       minval=0,
                                       maxval=2,
                                       dtype=tf.int32)
        is_blur = tf.random_uniform(shape=[],
                                    minval=0,
                                    maxval=2,
                                    dtype=tf.int32)
        image, gt_boxes = tf.cond(
            tf.equal(is_flip,
                     1), lambda: self.flip_left_right(image, gt_boxes), lambda:
            (image, gt_boxes))
        image, gt_boxes = tf.cond(
            tf.equal(is_distort,
                     1), lambda: self.random_distort_color(image, gt_boxes),
            lambda: (image, gt_boxes))
        image, gt_boxes = tf.cond(tf.equal(is_blur, 1),
                                  lambda: self.random_blur(image, gt_boxes),
                                  lambda: (image, gt_boxes))

        image, gt_boxes = utils.resize_image_correct_bbox(
            image, gt_boxes, self.image_h, self.image_w)

        if self.debug: return image, gt_boxes

        y_true = tf.py_func(self.preprocess_true_boxes,
                            inp=[gt_boxes],
                            Tout=tf.float32)
        image = image / 255.

        return image, y_true
model = yolov3.yolov3(80)
with tf.variable_scope('yolov3'):
    feature_maps = model.forward(inputs, is_training=True)
    load_ops = utils.load_weights(tf.global_variables(scope='yolov3'),
                                  "./checkpoint/yolov3.weights")
    sess.run(load_ops)
    loss = model.compute_loss(feature_maps, [y_true_13, y_true_26, y_true_52])

optimizer = tf.train.GradientDescentOptimizer(0.001)
train_op = optimizer.minimize(loss)
sess.run(tf.global_variables_initializer())

for image_path in dataset.keys():
    image = Image.open(image_path)
    true_boxes, true_labels = dataset[image_path]
    image, true_boxes = utils.resize_image_correct_bbox(
        image, true_boxes, input_shape)
    scores = np.ones(len(true_boxes))
    # utils.draw_boxes(image, boxes, scores, labels, classes)
    true_boxes = np.expand_dims(true_boxes, 0)
    true_labels = np.expand_dims(true_labels, 0)
    y_true = utils.preprocess_true_boxes(true_boxes, true_labels, input_shape,
                                         anchors, num_classes)

    image_data = np.expand_dims(np.array(image, dtype=np.float32) / 255.,
                                axis=0)

    _, result = sess.run(
        [train_op, loss],
        feed_dict={
            inputs: image_data,
            y_true_13: y_true[0],