예제 #1
0
    def test_basic_attributes(self):
        """Setup network and check basic parameters like TF variable names,
        number of layers, size of last feature map...
        """
        ft_dim = Shape(None, 64, 64)
        num_cls, num_layers = 10, 7

        # Compute the image dimensions required for a 2x2 feature size.
        im_dim = orpac_net.waveletToImageDim(ft_dim)

        net = orpac_net.Orpac(self.sess, im_dim, num_layers, num_cls, None, False)
        self.sess.run(tf.global_variables_initializer())
        assert net.session() is self.sess

        # The feature size must be 1/8 of the image size because the network
        # downsamples every second layer, and we specified 7 layers.
        assert num_layers == net.numLayers() == 7
        assert net.outputShape().hw() == ft_dim.hw()

        # Ensure we can query all biases and weights. Also verify the data type
        # inside the network.
        g = tf.get_default_graph().get_tensor_by_name
        for i in range(num_layers):
            # These must exist in the graph.
            assert g(f'orpac/W{i}:0') is not None
            assert g(f'orpac/b{i}:0') is not None
            assert net.getBias(i).dtype == np.float32
            assert net.getWeight(i).dtype == np.float32
예제 #2
0
    def test_feature_to_image_conversions(self):
        ft_dim = Shape(chan=None, height=2, width=2)

        # The two methods must be inverses of each other.
        im_dim = orpac_net.waveletToImageDim(ft_dim)
        assert orpac_net.imageToWaveletDim(im_dim) == ft_dim

        # Manually check the value as well. For each Wavelet decomposition of
        # the original input image the dimensions must have been halved.
        # Conversely, for any given feature map size, the corresponding image
        # size must be 2 ** num_decompositions in each dimension.
        rat = 2 ** orpac_net.Orpac._NUM_WAVELET_DECOMPOSITIONS
        assert im_dim.chw() == (None, ft_dim.height * rat, ft_dim.width * rat)
예제 #3
0
    def setup_class(cls):
        # Feature dimension will only be 2x2 to simplify testing and debugging.
        ft_dim = Shape(None, 64, 64)
        num_cls, num_layers = 10, 7

        # Compute the image dimensions required for a 2x2 feature size.
        im_dim = orpac_net.waveletToImageDim(ft_dim)

        # Create Tensorflow session and dummy network. The network is such that
        # the feature size is only 2x2 because this makes testing easier.
        cls.sess = tf.Session()
        cls.net = orpac_net.Orpac(
            cls.sess, im_dim, num_layers, num_cls, None, train=False)
        assert cls.net.outputShape().hw() == ft_dim.hw()
예제 #4
0
    def loadRawData(self, path, ft_dim, num_samples):
        """Return feature and label vector for data set of choice.

        Returns:
            im_dim: Shape
                Image shape
            ft_dim: Shape
                Dimensions of training data.
            int2name: dict[int:str]
                A LUT to translate machine labels to human readable strings.
                For instance {0: 'None', 1: 'Cube 0', 2: 'Cube 1'}.
            train: N-List[TrainingSample]
                Training data.
        """
        # Compile a list of JPG images in the source folder. Then verify that
        # a) each is a valid JPG file and b) all images have the same size.
        fnames = self.findTrainingFiles(path, num_samples)

        # Load and verify that the pickled meta data for each JPG file
        # specifies the same set of class labels.
        int2name = self.getLabelData(fnames)
        num_cls = len(int2name)

        # Compute the height and width that input images must have to be
        # compatible with the selected output feature size.
        im_dim = orpac_net.waveletToImageDim(Shape(None, *ft_dim.hw()))

        # Fill in channel information: Images must always be RGB and the
        # feature output channels are available via a utility method.
        im_dim.chan = 3
        ft_dim.chan = orpac_net.Orpac.numOutputChannels(num_cls)

        # Compile all the features that have not been compiled already.
        self.compileMissingFeatures(fnames, ft_dim)

        # Load the compiled training data alongside each image.
        train = self.loadTrainingData(fnames, im_dim, ft_dim, num_cls)
        return im_dim, ft_dim, int2name, train
예제 #5
0
    def setup_class(cls):
        # Feature dimension will only be 2x2 to simplify testing and debugging.
        ft_dim = Shape(None, 2, 2)
        num_cls, num_layers = 10, 7

        # Compute the image dimensions required for a 2x2 feature size.
        im_dim = orpac_net.waveletToImageDim(ft_dim)

        # Create Tensorflow session and dummy network. The network is such that
        # the feature size is only 2x2 because this makes testing easier.
        cls.sess = tf.Session()
        cls.net = orpac_net.Orpac(
            cls.sess, im_dim, num_layers, num_cls, None, train=False)
        assert cls.net.outputShape().hw() == (2, 2)

        # A dummy feature tensor that we will populate it with our own data to
        # simulate the network output. To create it we simply "clone" the
        # genuine network output tensor.
        cls.y_pred_in = tf.placeholder(tf.float32, cls.net.output().shape)

        # Setup cost computation. This will create a node for `y_true`.
        cls.total_cost = orpac_net.createCostNodes(cls.y_pred_in)
        g = tf.get_default_graph().get_tensor_by_name
        cls.y_true_in = g('orpac-cost/y_true:0')