示例#1
0
    def test_train(self):
        """Ensure the 'train' method succeeds.

        This test does not assess the numerical output but merely ensures the
        method works when the provided parameters have the correct shape and
        type.
        """
        im_dim = Shape(3, 64, 64)
        num_cls, num_layers = 10, 7

        # Create trainable network with random weights.
        net = orpac_net.Orpac(self.sess, im_dim, num_layers, num_cls, None, True)
        self.sess.run(tf.global_variables_initializer())
        assert net.trainable() is True

        # Create dummy learning rate, image and training output.
        lrate = 1E-5
        ft_dim = net.outputShape()
        y = np.random.uniform(0, 256, ft_dim.chw()).astype(np.uint8)
        img = np.random.randint(0, 256, im_dim.hwc()).astype(np.uint8)

        # Create dummy masks.
        mask_cls = np.random.randint(0, 2, ft_dim.hw()).astype(np.float32)
        mask_bbox = np.random.randint(0, 2, ft_dim.hw()).astype(np.float32)
        mask_isFg = np.random.randint(0, 2, ft_dim.hw()).astype(np.float32)

        # 'Train' method must complete without error and return the costs.
        costs = net.train(img, y, lrate, mask_cls, mask_bbox, mask_isFg)
        assert isinstance(costs, dict)
        assert set(costs.keys()) == {'cls', 'bbox', 'isFg', 'total'}
示例#2
0
    def test_imageToInput(self):
        """Uint8 image must becomes a valid network input."""
        num_layers = 7
        im_dim = Shape(3, 512, 512)
        img = 100 * np.ones(im_dim.hwc(), np.uint8)

        # Create a network (parameters do not matter).
        net = orpac_net.Orpac(self.sess, im_dim, num_layers, 10, None, False)

        # Image must be converted to float32 CHW image with leading
        # batch dimension of 1. All values must have been divided by 255.
        img_wl = net._imageToInput(img)
        dim_xin = Shape(int(net._xin.shape[1]), *net.outputShape().hw())
        assert img_wl.dtype == np.float32
        assert img_wl.shape == (1, *dim_xin.chw())
示例#3
0
    def test_predict(self):
        """Ensure the 'predict' method succeeds.

        This test does not assess the numerical output but merely ensures the
        method works when the provided parameters have the correct shape and
        type.

        """
        im_dim = Shape(3, 64, 64)
        num_cls, num_layers = 10, 7

        # Create predictor-only network with random weights.
        net = orpac_net.Orpac(self.sess, im_dim, num_layers, num_cls, None, False)
        self.sess.run(tf.global_variables_initializer())
        assert net.trainable() is not True

        # Create dummy learning rate, image and training output.
        img = np.random.randint(0, 256, im_dim.hwc()).astype(np.uint8)

        # 'Train' method must complete without error and return the costs.
        y = net.predict(img)
        assert isinstance(y, np.ndarray) and y.dtype == np.float32
        assert y.shape == net.outputShape().chw()