def run()

in libraries/python/coco/generate_im_info.py [0:0]


    def run(self):
        with open(self.args.dataset_file, "r") as f:
            imgs = [json.loads(s) for s in f.readlines()]
        batch_size = self.args.batch_size if self.args.batch_size > 0 else len(imgs)

        num_batches = len(imgs) // batch_size
        assert len(imgs) == num_batches * batch_size
        im_infos = []
        for i in range(num_batches):
            one_batch_info = []
            for j in range(i * batch_size, (i + 1) * batch_size):
                img = imgs[j]
                im_scale = self.getScale(img["height"], img["width"])
                height = int(np.round(img["height"] * im_scale))
                width = int(np.round(img["width"] * im_scale))
                assert (
                    height <= self.args.max_size
                ), "height {} is more than the max_size {}".format(
                    height, self.args.max_size
                )
                assert (
                    width <= self.args.max_size
                ), "width {} is more than the max_size {}".format(
                    width, self.args.max_size
                )
                if height < self.args.min_size or width < self.args.min_size:
                    assert height == self.args.max_size or width == self.args.max_size
                else:
                    assert height == self.args.min_size or width == self.args.min_size
                im_info = [height, width, im_scale]
                one_batch_info.append(im_info)
            im_infos.append(one_batch_info)

        with open(self.args.output_file, "w") as f:
            f.write("{}, {}\n".format(num_batches * batch_size, 3))
            for batch in im_infos:
                for im_info in batch:
                    s = ", ".join([str(s) for s in im_info])
                    f.write("{}\n".format(s))