Exemple #1
0
                                bbe_2dtensor=bbe_2dtensor)

        _, ax = plt.subplots(figsize=(15, 7.35))
        ax.imshow(x / 255)

        # iterate over rois
        for k in range(pred_bbox2d.shape[0]):

            print(np.array(clz_2dtensor[k]))
            # print('{} -> {}'.format(k, classes[clz]))

            clz = np.argmax(clz_2dtensor[k])
            roi = roi_2dtensor[k]
            bbox = pred_bbox2d[k]

            rframe = box2frame(box=roi, apoint=[0, 0])

            ax.add_patch(
                Rectangle((rframe[0], rframe[1]),
                          rframe[2],
                          rframe[3],
                          linewidth=1,
                          edgecolor='r',
                          facecolor='none',
                          linestyle='-'))

            tframe = box2frame(box=bbox, apoint=[0.5, 0.5])

            ax.annotate(classes[clz], (tframe[0], tframe[1]),
                        color='green',
                        weight='bold',
Exemple #2
0
	fg_3dtensor = clz_4dtensor[:, :, :, 0]
	bg_3dtensor = clz_4dtensor[:, :, :, 1]
	
	fg_indices = tf.where(condition=tf.math.equal(x=fg_3dtensor, y=1.0))
	fg_anchor_2dtensor = tf.gather_nd(params=anchor_4dtensor, indices=fg_indices)
	fg_2dtensor = tf.gather_nd(params=bbox_4dtensor, indices=fg_indices)
	
	bg_indices = tf.where(condition=tf.math.equal(x=bg_3dtensor, y=1.0))
	bg_anchor_2dtensor = tf.gather_nd(params=anchor_4dtensor, indices=bg_indices)

	ax.imshow(x/255)
	ax.set_xlabel('Order: {}, Image ID: {}'.format(sample_order, img_id))
	
	for i in range(fg_anchor_2dtensor.shape[0]):
		box = np.array(fg_anchor_2dtensor[i], dtype='float32')
		frame = box2frame(box=box, apoint=[0, 0])
		ax.add_patch(Rectangle(
			(frame[0], frame[1]), frame[2], frame[3],
			linewidth=0.8, 
			edgecolor='cyan',
			facecolor='none', 
			linestyle='-'))

		box = np.array(fg_2dtensor[i], dtype='float32')
		frame = box2frame(box=box, apoint=[0, 0])
		ax.add_patch(Rectangle(
			(frame[0], frame[1]), frame[2], frame[3],
			linewidth=1.0, 
			edgecolor='yellow',
			facecolor='none', 
			linestyle='-'))
Exemple #3
0
                                     axis=0)  # (h, w, k, 1)
    sum_neg_4dtensor = tf.reduce_sum(input_tensor=neg_5dtensor,
                                     axis=0)  # (h, w, k, 1)

    # Shows
    sum_pos_4dtensor = np.array(sum_pos_4dtensor)
    sum_neg_4dtensor = np.array(sum_neg_4dtensor)

    ax.imshow(x / 255)
    ax.set_xlabel('Order: {}, Image ID: {}'.format(sample_order, img_id))

    for h in range(H):
        for w in range(W):
            for k in range(K):

                frame = box2frame(box=abox4d[h, w, k], apoint=[0, 0])

                # positive anchors
                if sum_pos_4dtensor[h, w, k, 0] > 0.0:
                    if True:
                        ax.add_patch(
                            Rectangle((frame[0], frame[1]),
                                      frame[2],
                                      frame[3],
                                      linewidth=1,
                                      edgecolor='cyan',
                                      facecolor='none',
                                      linestyle='-'))

                # negative anchors
                if sum_neg_4dtensor[h, w, k, 0] == -num_of_bboxes:
Exemple #4
0
def update(routes, boxes, clean_after, min_frame_of_pos_route):
    '''
	To do:
		- Add boxes to the suitable routes
		- Remmove invalid routes
	Arguments
		routes: list of integers and tuples, tuples are points
		boxes:
		clean_after:
		min_frame_of_pos_route:
	Note
		16777216 = 256*256*256 which is r*g*b
	'''

    if len(boxes) == 0:
        return

    if len(routes) == 0:
        for box in boxes:
            routes.append([random.randint(0, 16777216), box2frame(box)])
        return

    added_route_indices = []

    for box in boxes:
        frame = box2frame(box)
        added = False
        removed = []

        for i in range(len(routes)):

            if i in added_route_indices:
                continue

            route = routes[i]
            last_item = route[-1]
            if type(last_item) is int:
                if last_item == -1:
                    continue

                if last_item > clean_after:
                    removed.append(i)
                    continue

                routes[i][-1] += 1
                last_item = route[-2]

            if in_box(point=last_item[:2], box=box):
                routes[i].append(frame)
                added_route_indices.append(i)
                added = True
            else:
                if type(route[-1]) is int:
                    routes[i][-1] += 1
                else:
                    routes[i].append(1)

        # Remove invalid route after some frames
        for idx in sorted(removed, reverse=True):
            if len(routes[idx]) < min_frame_of_pos_route:
                del routes[idx]
            else:
                routes[idx].append(-1)  #no more adding for this route

        if added is not True:
            routes.append([random.randint(0, 16777216), frame])
Exemple #5
0
    _, ax = plt.subplots(figsize=(15, 7.35))

    num_of_rois = y_pred.shape[0]

    ax.imshow(x / 255)
    ax.set_xlabel('Order: {}, Image ID: {}'.format(sample_order, img_id))

    for k in range(num_of_rois):
        pclz = int(y_pred[k, 8])

        # if pclz == len(classes)-1:
        # 	continue

        rbox = np.array(y_pred[k, :4])
        pbox = np.array(y_pred[k, 4:8])
        tframe = box2frame(box=pbox, apoint=[0.5, 0.5])

        ax.annotate(classes[pclz], (tframe[0], tframe[1]),
                    color='green',
                    weight='bold',
                    fontsize=8,
                    ha='center',
                    va='center')

        rframe = box2frame(box=rbox, apoint=[0, 0])
        tframe = box2frame(box=pbox, apoint=[0, 0])

        ax.add_patch(
            Rectangle((rframe[0], rframe[1]),
                      rframe[2],
                      rframe[3],
Exemple #6
0
        sum_neg_4dtensor = tf.reduce_sum(input_tensor=neg_5dtensor,
                                         axis=0)  # (h, w, k, 1)

        # Shows
        sum_pos_4dtensor = np.array(sum_pos_4dtensor)
        sum_neg_4dtensor = np.array(sum_neg_4dtensor)

        ax[int(lvl / 2), lvl % 2].imshow(x / 255)
        ax[int(lvl / 2), lvl % 2].set_xlim([0, x.shape[1]])
        ax[int(lvl / 2), lvl % 2].set_ylim([x.shape[0], 0])

        for h in range(H):
            for w in range(W):
                for k in range(K):

                    frame = box2frame(box=anchor4d[h, w, k], apoint=[0, 0])

                    # positive anchors
                    if sum_pos_4dtensor[h, w, k, 0] > 0.0:
                        if True:
                            ax[int(lvl / 2), lvl % 2].add_patch(
                                Rectangle((frame[0], frame[1]),
                                          frame[2],
                                          frame[3],
                                          linewidth=1,
                                          edgecolor='cyan',
                                          facecolor='none',
                                          linestyle='-'))

                    # negative anchors
                    if sum_neg_4dtensor[h, w, k, 0] == -num_of_bboxes:
Exemple #7
0
    bbe_2dtensor = clzbbe_2dtensor[:, len(classes):]

    pred_bbox2d = bbe2box2d(box_2dtensor=roi_2dtensor,
                            bbe_2dtensor=bbe_2dtensor)

    fig, ax = plt.subplots(figsize=(15, 7.35))
    ax.imshow(x / 255)

    for k in range(roi_2dtensor.shape[0]):
        clz1d = np.array(clz_2dtensor[k])  # onehot
        if np.sum(clz1d) == 0:
            continue

        clz = np.argmax(clz1d)
        pred_bbox = pred_bbox2d[k]
        tframe = box2frame(box=pred_bbox, apoint=[0.5, 0.5])

        ax.annotate(classes[clz], (tframe[0], tframe[1]),
                    color='green',
                    weight='bold',
                    fontsize=8,
                    ha='center',
                    va='center')

        tframe = box2frame(box=pred_bbox, apoint=[0.0, 0.0])

        ax.add_patch(
            Rectangle((tframe[0], tframe[1]),
                      tframe[2],
                      tframe[3],
                      linewidth=1,