Ejemplo n.º 1
0
	def call(self, x):
		'''
		To compute final output from classification branch and location branch
		Arguments
			x:
		Return
			tensor
		'''

		assert len(x) == 2, 'OutputLayer must be passed 2 inputs: clzbbe_tensor and roi_tensor'

		clzbbe_3dtensor = x[0] # (batch_size, num_of_rois, num_of_classes+4), batch_size = 1
		num_of_class = clzbbe_3dtensor.shape[2]-4 
		clz_2dtensor = clzbbe_3dtensor[0, :, :num_of_class] # (num_of_rois, num_of_classes)
		bbe_2dtensor = clzbbe_3dtensor[0, :, num_of_class:] # (num_of_rois, 4)
		roi_3dtensor = x[1] # (batch_size, num_of_rois, 4), batch_size = 1
		roi_2dtensor = roi_3dtensor[0] # (num_of_rois, 4)

		pbox_2dtensor = bbe2box2d(box_2dtensor=roi_2dtensor, bbe_2dtensor=bbe_2dtensor)
		clz_3dtensor = tf.expand_dims(input=clz_2dtensor, axis=2)
		pclzprob = tf.math.reduce_max(input_tensor=clz_3dtensor, axis=1)
		pclz = tf.math.argmax(input=clz_3dtensor, axis=1)
		pclz = tf.cast(pclz, dtype='float32')

		t = tf.concat(values=[roi_2dtensor, pbox_2dtensor, pclz, pclzprob], axis=1)

		return t
Ejemplo n.º 2
0
        # predict rois
        roi2d = pad_roi2d(roi2d=bbox2d[:, :4],
                          max_num_of_rois=max_num_of_rois,
                          pad_roi=[0, 0, ishape[0], ishape[1]])
        roi_2dtensor = tf.constant(value=roi2d, dtype='float32')

        # predict object proposal
        batch_x = [
            tf.expand_dims(input=x, axis=0),
            tf.expand_dims(input=roi_2dtensor, axis=0)
        ]
        y_pred = detection_model.predict_on_batch(batch_x)
        clzbbe_tensor = y_pred[0]
        clz_2dtensor = clzbbe_tensor[:, :len(classes)]
        bbe_2dtensor = clzbbe_tensor[:, len(classes):]
        pred_bbox2d = bbe2box2d(box_2dtensor=roi_2dtensor,
                                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])