예제 #1
0
    def __init__(
        self,
        prev_layer,
        rois,
        pool_height=2,
        pool_width=2,
        name='roipooling_layer',
    ):
        super(ROIPoolingLayer, self).__init__(prev_layer=prev_layer, name=name)
        logging.info("ROIPoolingLayer %s: (%d, %d)" %
                     (name, pool_height, pool_width))

        self.inputs = prev_layer.outputs

        try:
            from tensorlayer.third_party.roi_pooling.roi_pooling.roi_pooling_ops import roi_pooling
        except Exception as e:
            logging.info(e)
            logging.info(
                "HINT: 1. https://github.com/deepsense-ai/roi-pooling  2. tensorlayer/third_party/roi_pooling"
            )
        self.outputs = roi_pooling(self.inputs, rois, pool_height, pool_width)

        # self.all_layers = list(layer.all_layers)
        # self.all_params = list(layer.all_params)
        # self.all_drop = dict(layer.all_drop)
        self.all_layers.append(self.outputs)
예제 #2
0
    def __init__(
        self,
        #inputs = None,
        layer=None,
        rois=None,
        pool_height=2,
        pool_width=2,
        name='roipooling_layer',
    ):
        Layer.__init__(self, name=name)
        self.inputs = layer.outputs
        logging.info("ROIPoolingLayer %s: (%d, %d)" %
                     (self.name, pool_height, pool_width))
        try:
            from tensorlayer.third_party.roi_pooling.roi_pooling.roi_pooling_ops import roi_pooling
        except Exception as e:
            logging.info(e)
            logging.info(
                "\nHINT: \n1. https://github.com/deepsense-ai/roi-pooling  \n2. tensorlayer/third_party/roi_pooling\n"
            )
        self.outputs = roi_pooling(self.inputs, rois, pool_height, pool_width)

        self.all_layers = list(layer.all_layers)
        self.all_params = list(layer.all_params)
        self.all_drop = dict(layer.all_drop)
        self.all_layers.extend([self.outputs])
예제 #3
0
    def __init__(
        self,
        prev_layer,
        rois,
        pool_height=2,
        pool_width=2,
        name='roipooling_layer',
    ):
        super(ROIPoolingLayer, self).__init__(prev_layer=prev_layer, name=name)

        logging.info("ROIPoolingLayer %s: (%d, %d)" %
                     (name, pool_height, pool_width))

        self.inputs = prev_layer.outputs

        self.outputs = roi_pooling(self.inputs, rois, pool_height, pool_width)

        self.all_layers.append(self.outputs)
예제 #4
0
    def __init__(
            self,
            prev_layer,
            rois,
            pool_height=2,
            pool_width=2,
            name='roipooling_layer',
    ):
        Layer.__init__(self, prev_layer=prev_layer, name=name)
        self.inputs = prev_layer.outputs
        logging.info("ROIPoolingLayer %s: (%d, %d)" % (self.name, pool_height, pool_width))
        try:
            from tensorlayer.third_party.roi_pooling.roi_pooling.roi_pooling_ops import roi_pooling
        except Exception as e:
            logging.info(e)
            logging.info("HINT: 1. https://github.com/deepsense-ai/roi-pooling  2. tensorlayer/third_party/roi_pooling")
        self.outputs = roi_pooling(self.inputs, rois, pool_height, pool_width)

        # self.all_layers = list(layer.all_layers)
        # self.all_params = list(layer.all_params)
        # self.all_drop = dict(layer.all_drop)
        self.all_layers.append(self.outputs)
예제 #5
0
# y = roi_pooling(input, rois, pool_height=2, pool_width=2)
n = InputLayer(input, name='in')
n = ROIPoolingLayer(n, rois=rois, pool_height=2, pool_width=2, name='roi')
y = n.outputs
mean = tf.reduce_mean(y)

grads = tf.gradients(mean, input)
print(type(grads))
print(len(grads))
print(grads)
print(input_value.shape)

with tf.Session('') as sess:
    input_const = tf.constant(input_value, tf.float32)
    rois_const = tf.constant(rois_value, tf.int32)
    y = roi_pooling(input_const, rois_const, pool_height=2, pool_width=2)
    mean = tf.reduce_mean(y)

    numerical_grad_error_1 = tf.test.compute_gradient_error(
        [input_const], [input_value.shape], y, y_shape)
    numerical_grad_error_2 = tf.test.compute_gradient_error(
        [input_const], [input_value.shape], mean, [])
    print(numerical_grad_error_1, numerical_grad_error_2)

with tf.Session('') as sess:
    y_output = sess.run(y, feed_dict={input: input_value, rois: rois_value})
    print('y: ', y_output)
    grads_output = sess.run(grads,
                            feed_dict={
                                input: input_value,
                                rois: rois_value
예제 #6
0
input = tf.compat.v1.placeholder(tf.float32)
rois = tf.compat.v1.placeholder(tf.int32)

# y = roi_pooling(input, rois, pool_height=2, pool_width=2)
n = InputLayer(input, name='in')
n = ROIPoolingLayer(n, rois=rois, pool_height=2, pool_width=2, name='roi')
y = n.outputs
mean = tf.reduce_mean(input_tensor=y)

grads = tf.gradients(mean, input)
print(type(grads))
print(len(grads))
print(grads)
print(input_value.shape)

with tf.compat.v1.Session('') as sess:
    input_const = tf.constant(input_value, tf.float32)
    rois_const = tf.constant(rois_value, tf.int32)
    y = roi_pooling(input_const, rois_const, pool_height=2, pool_width=2)
    mean = tf.reduce_mean(input_tensor=y)

    numerical_grad_error_1 = tf.compat.v1.test.compute_gradient_error([input_const], [input_value.shape], y, y_shape)
    numerical_grad_error_2 = tf.compat.v1.test.compute_gradient_error([input_const], [input_value.shape], mean, [])
    print(numerical_grad_error_1, numerical_grad_error_2)

with tf.compat.v1.Session('') as sess:
    y_output = sess.run(y, feed_dict={input: input_value, rois: rois_value})
    print('y: ', y_output)
    grads_output = sess.run(grads, feed_dict={input: input_value, rois: rois_value})
    print('grads: ', grads_output)