def _prepare_img_to_run(self, img):
     assert self.nn.batch_size == 1, \
             "batch_size of runner is not 1, but trying to run against 1 image"
     img = get_image_matrix(img, show=False)
     # shape could be (x, y) or (3, x, y)
     assert img.shape in [self.nn.input_shape[1:], self.nn.input_shape[2:]]
     return img.flatten()
Exemple #2
0
    def run_batch(self, imgs):
        nr_img = len(imgs)
        assert all([img.shape[:2] == self.input_shape for img in imgs])

        def preprocess(img):
            img = mean_subtract(img)
            return img * 2.0 / 255 - 1

        # to ic01
        images_to_run = np.asarray(
            [get_image_matrix(preprocess(m), False) for m in imgs])

        results = []
        nowid = 0
        for k in reversed(self.BATCHES):
            nn = self.nns[k]
            while nr_img >= k:
                print k
                inputs = images_to_run[nowid:nowid + k]
                inputs = inputs.reshape((k, -1))
                outputs = nn.func(inputs)
                results.append(outputs)
                nr_img -= k
                nowid += k
        results = np.concatenate(results, axis=0)
        return results
Exemple #3
0
 def _prepare_img_to_run(self, img):
     assert self.nn.batch_size == 1, \
             "batch_size of runner is not 1, but trying to run against 1 image"
     img = get_image_matrix(img, show=False)
     # shape could be (x, y) or (3, x, y)
     assert img.shape in [self.nn.input_shape[1:], self.nn.input_shape[2:]]
     return img.flatten()
Exemple #4
0
    def run_batch(self, imgs):
        nr_img = len(imgs)
        assert all([img.shape[:2] == self.input_shape for img in imgs])
        def preprocess(img):
            img = mean_subtract(img)
            return img * 2.0 / 255 - 1
        # to ic01
        images_to_run = np.asarray(
            [get_image_matrix(preprocess(m), False) for m in imgs])

        results = []
        nowid = 0
        for k in reversed(self.BATCHES):
            nn = self.nns[k]
            while nr_img >= k:
                print k
                inputs = images_to_run[nowid:nowid+k]
                inputs = inputs.reshape((k, -1))
                outputs = nn.func(inputs)
                results.append(outputs)
                nr_img -= k
                nowid += k
        results = np.concatenate(results, axis=0)
        return results