当前位置: 首页>>代码示例>>Python>>正文


Python utils.apply_to_iterator方法代码示例

本文整理汇总了Python中chainercv.utils.apply_to_iterator方法的典型用法代码示例。如果您正苦于以下问题:Python utils.apply_to_iterator方法的具体用法?Python utils.apply_to_iterator怎么用?Python utils.apply_to_iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainercv.utils的用法示例。


在下文中一共展示了utils.apply_to_iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_apply_to_iterator_with_infinite_iterator

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def test_apply_to_iterator_with_infinite_iterator(self):
        def func(*in_values):
            n_sample = len(in_values[0])
            return [np.random.uniform(size=(48, 64)) for _ in range(n_sample)]

        dataset = []
        for _ in range(5):
            H, W = np.random.randint(8, 16, size=2)
            dataset.append(np.random.randint(0, 256, size=(3, H, W)))

        iterator = SerialIterator(dataset, 2)

        in_values, out_values, rest_values = apply_to_iterator(func, iterator)

        for _ in range(10):
            next(in_values[0])

        for _ in range(10):
            next(out_values[0]) 
开发者ID:chainer,项目名称:chainercv,代码行数:21,代码来源:test_apply_to_iterator.py

示例2: evaluate

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def evaluate(self):
        iterator = self._iterators['main']
        target = self._targets['main']

        if hasattr(iterator, 'reset'):
            iterator.reset()
            it = iterator
        else:
            it = copy.copy(iterator)

        in_values, out_values, rest_values = apply_to_iterator(
            target.predict, it)
        # delete unused iterators explicitly
        del in_values

        points, labels, scores = out_values
        gt_points, gt_labels = rest_values

        result = eval_projected_3d_bbox_single(
            points, scores, gt_points,
            self.vertex, self.intrinsics, diam=self.diam)
        report = result

        observation = {}
        with reporter.report_scope(observation):
            reporter.report(report, target)
        return observation 
开发者ID:chainer,项目名称:models,代码行数:29,代码来源:projected_3d_bbox_evaluator.py

示例3: main

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--gpu', type=int, default=-1)
    parser.add_argument('--pretrained-model')
    args = parser.parse_args()

    model = ResNet50(
        pretrained_model=args.pretrained_model,
        n_class=len(voc_bbox_label_names), arch='he')
    model.pick = 'fc6'
    if args.gpu >= 0:
        chainer.cuda.get_device_from_id(args.gpu).use()
        model.to_gpu()

    dataset = VOCBboxDataset(
        split='test', year='2007', use_difficult=False)
    dataset = TransformDataset(
        dataset, ('img', 'bbox'), bbox_to_multi_label)
    iterator = iterators.SerialIterator(
        dataset, 8, repeat=False, shuffle=False)

    in_values, out_values, rest_values = apply_to_iterator(
        PredictFunc(model, thresh=0), iterator,
        hook=ProgressHook(len(dataset)))
    # delete unused iterators explicitly
    del in_values
    pred_labels, pred_scores = out_values
    gt_labels, = rest_values

    result = eval_multi_label_classification(
        pred_labels, pred_scores, gt_labels)
    print()
    print('mAP: {:f}'.format(result['map']))
    for l, name in enumerate(voc_bbox_label_names):
        if result['ap'][l]:
            print('{:s}: {:f}'.format(name, result['ap'][l]))
        else:
            print('{:s}: -'.format(name)) 
开发者ID:chainer,项目名称:models,代码行数:40,代码来源:eval_voc07.py

示例4: evaluate

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def evaluate(self):
        iterator = self._iterators['main']
        target = self._targets['main']

        if hasattr(iterator, 'reset'):
            iterator.reset()
            it = iterator
        else:
            it = copy.copy(iterator)

        in_values, out_values, rest_values = apply_to_iterator(
            self.predict_func, it)
        # delete unused iterators explicitly
        del in_values

        pred_labels, pred_scores = out_values
        gt_labels, = rest_values

        result = eval_multi_label_classification(
            pred_labels, pred_scores, gt_labels)

        report = {'map': result['map']}

        if self.label_names is not None:
            for l, label_name in enumerate(self.label_names):
                try:
                    report['ap/{:s}'.format(label_name)] = result['ap'][l]
                except IndexError:
                    report['ap/{:s}'.format(label_name)] = np.nan

        observation = {}
        with reporter.report_scope(observation):
            reporter.report(report, target)
        return observation 
开发者ID:chainer,项目名称:models,代码行数:36,代码来源:multi_label_classification_evaluator.py

示例5: main

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--dataset', choices=('cityscapes', 'ade20k', 'camvid', 'voc'))
    parser.add_argument('--model', choices=sorted(models.keys()))
    parser.add_argument('--gpu', type=int, default=-1)
    parser.add_argument('--pretrained-model')
    parser.add_argument('--batchsize', type=int)
    parser.add_argument('--input-size', type=int, default=None)
    args = parser.parse_args()

    dataset, eval_, model, batchsize = setup(
        args.dataset, args.model, args.pretrained_model,
        args.batchsize, args.input_size)

    if args.gpu >= 0:
        chainer.cuda.get_device_from_id(args.gpu).use()
        model.to_gpu()

    iterator = iterators.SerialIterator(
        dataset, batchsize, repeat=False, shuffle=False)

    in_values, out_values, rest_values = apply_to_iterator(
        model.predict, iterator, hook=ProgressHook(len(dataset)))
    # Delete an iterator of images to save memory usage.
    del in_values

    eval_(out_values, rest_values) 
开发者ID:chainer,项目名称:chainercv,代码行数:30,代码来源:eval_semantic_segmentation.py

示例6: main

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--dataset', choices=('cityscapes', 'ade20k', 'camvid', 'voc'))
    parser.add_argument('--model', choices=sorted(models.keys()))
    parser.add_argument('--pretrained-model')
    parser.add_argument('--batchsize', type=int)
    parser.add_argument('--input-size', type=int, default=None)
    args = parser.parse_args()

    comm = chainermn.create_communicator('pure_nccl')
    device = comm.intra_rank

    dataset, eval_, model, batchsize = setup(
        args.dataset, args.model, args.pretrained_model,
        args.batchsize, args.input_size)

    chainer.cuda.get_device_from_id(device).use()
    model.to_gpu()

    if not comm.rank == 0:
        apply_to_iterator(model.predict, None, comm=comm)
        return

    it = iterators.MultithreadIterator(
        dataset, batchsize * comm.size, repeat=False, shuffle=False)

    in_values, out_values, rest_values = apply_to_iterator(
        model.predict, it, hook=ProgressHook(len(dataset)), comm=comm)
    # Delete an iterator of images to save memory usage.
    del in_values

    eval_(out_values, rest_values) 
开发者ID:chainer,项目名称:chainercv,代码行数:35,代码来源:eval_semantic_segmentation_multi.py

示例7: main

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--dataset', choices=('voc', 'coco'))
    parser.add_argument('--model', choices=sorted(models.keys()))
    parser.add_argument('--pretrained-model')
    parser.add_argument('--batchsize', type=int)
    parser.add_argument('--gpu', type=int, default=-1)
    args = parser.parse_args()

    dataset, eval_, model, batchsize = setup(
        args.dataset, args.model, args.pretrained_model, args.batchsize)

    if args.gpu >= 0:
        chainer.cuda.get_device_from_id(args.gpu).use()
        model.to_gpu()

    model.use_preset('evaluate')

    iterator = iterators.MultithreadIterator(
        dataset, batchsize, repeat=False, shuffle=False)

    in_values, out_values, rest_values = apply_to_iterator(
        model.predict, iterator, hook=ProgressHook(len(dataset)))
    # delete unused iterators explicitly
    del in_values

    eval_(out_values, rest_values) 
开发者ID:chainer,项目名称:chainercv,代码行数:29,代码来源:eval_detection.py

示例8: main

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--dataset', choices=('voc', 'coco'))
    parser.add_argument('--model', choices=sorted(models.keys()))
    parser.add_argument('--pretrained-model')
    parser.add_argument('--batchsize', type=int)
    args = parser.parse_args()

    comm = chainermn.create_communicator('pure_nccl')
    device = comm.intra_rank

    dataset, eval_, model, batchsize = setup(
        args.dataset, args.model, args.pretrained_model, args.batchsize)

    chainer.cuda.get_device_from_id(device).use()
    model.to_gpu()

    model.use_preset('evaluate')

    if not comm.rank == 0:
        apply_to_iterator(model.predict, None, comm=comm)
        return

    iterator = iterators.MultithreadIterator(
        dataset, batchsize * comm.size, repeat=False, shuffle=False)

    in_values, out_values, rest_values = apply_to_iterator(
        model.predict, iterator, hook=ProgressHook(len(dataset)), comm=comm)
    # delete unused iterators explicitly
    del in_values

    eval_(out_values, rest_values) 
开发者ID:chainer,项目名称:chainercv,代码行数:34,代码来源:eval_detection_multi.py

示例9: main

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def main():
    parser = argparse.ArgumentParser(
        description='Evaluating convnet from ILSVRC2012 dataset')
    parser.add_argument('val', help='Path to root of the validation dataset')
    parser.add_argument('--model', choices=sorted(models.keys()))
    parser.add_argument('--pretrained-model')
    parser.add_argument('--dataset', choices=('imagenet',))
    parser.add_argument('--gpu', type=int, default=-1)
    parser.add_argument('--batchsize', type=int)
    parser.add_argument('--crop', choices=('center', '10'))
    parser.add_argument('--resnet-arch')
    args = parser.parse_args()

    dataset, eval_, model, batchsize = setup(
        args.dataset, args.model, args.pretrained_model, args.batchsize,
        args.val, args.crop, args.resnet_arch)

    if args.gpu >= 0:
        chainer.cuda.get_device(args.gpu).use()
        model.to_gpu()

    iterator = iterators.MultiprocessIterator(
        dataset, batchsize, repeat=False, shuffle=False,
        n_processes=6, shared_mem=300000000)

    print('Model has been prepared. Evaluation starts.')
    in_values, out_values, rest_values = apply_to_iterator(
        model.predict, iterator, hook=ProgressHook(len(dataset)))
    del in_values

    eval_(out_values, rest_values) 
开发者ID:chainer,项目名称:chainercv,代码行数:33,代码来源:eval_imagenet.py

示例10: main

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--dataset', choices=('sbd', 'coco'))
    parser.add_argument('--model', choices=sorted(models.keys()))
    parser.add_argument('--pretrained-model')
    parser.add_argument('--batchsize', type=int)
    args = parser.parse_args()

    comm = chainermn.create_communicator('pure_nccl')
    device = comm.intra_rank

    dataset, eval_, model, batchsize = setup(
        args.dataset, args.model, args.pretrained_model, args.batchsize)

    chainer.cuda.get_device_from_id(device).use()
    model.to_gpu()

    if not comm.rank == 0:
        apply_to_iterator(model.predict, None, comm=comm)
        return

    iterator = iterators.MultithreadIterator(
        dataset, batchsize * comm.size, repeat=False, shuffle=False)

    in_values, out_values, rest_values = apply_to_iterator(
        model.predict, iterator, hook=ProgressHook(len(dataset)), comm=comm)
    # delete unused iterators explicitly
    del in_values

    eval_(out_values, rest_values) 
开发者ID:chainer,项目名称:chainercv,代码行数:32,代码来源:eval_instance_segmentation_multi.py

示例11: evaluate

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def evaluate(self):
        target = self._targets['main']
        if self.comm is not None and self.comm.rank != 0:
            apply_to_iterator(target.predict, None, comm=self.comm)
            return {}
        iterator = self._iterators['main']

        if hasattr(iterator, 'reset'):
            iterator.reset()
            it = iterator
        else:
            it = copy.copy(iterator)

        in_values, out_values, rest_values = apply_to_iterator(
            target.predict, it, comm=self.comm)
        # delete unused iterators explicitly
        del in_values

        pred_labels, = out_values
        gt_labels, = rest_values

        result = eval_semantic_segmentation(pred_labels, gt_labels)

        report = {'miou': result['miou'],
                  'pixel_accuracy': result['pixel_accuracy'],
                  'mean_class_accuracy': result['mean_class_accuracy']}

        if self.label_names is not None:
            for l, label_name in enumerate(self.label_names):
                try:
                    report['iou/{:s}'.format(label_name)] = result['iou'][l]
                    report['class_accuracy/{:s}'.format(label_name)] =\
                        result['class_accuracy'][l]
                except IndexError:
                    report['iou/{:s}'.format(label_name)] = np.nan
                    report['class_accuracy/{:s}'.format(label_name)] = np.nan

        observation = {}
        with reporter.report_scope(observation):
            reporter.report(report, target)
        return observation 
开发者ID:chainer,项目名称:chainercv,代码行数:43,代码来源:semantic_segmentation_evaluator.py

示例12: evaluate

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def evaluate(self):
        target = self._targets['main']
        if self.comm is not None and self.comm.rank != 0:
            apply_to_iterator(target.predict, None, comm=self.comm)
            return {}

        iterator = self._iterators['main']

        if hasattr(iterator, 'reset'):
            iterator.reset()
            it = iterator
        else:
            it = copy.copy(iterator)

        in_values, out_values, rest_values = apply_to_iterator(
            target.predict, it, comm=self.comm)
        # delete unused iterators explicitly
        del in_values

        pred_masks, pred_labels, pred_scores = out_values
        gt_masks, gt_labels = rest_values

        result = eval_instance_segmentation_voc(
            pred_masks, pred_labels, pred_scores,
            gt_masks, gt_labels,
            iou_thresh=self.iou_thresh,
            use_07_metric=self.use_07_metric)

        report = {'map': result['map']}

        if self.label_names is not None:
            for l, label_name in enumerate(self.label_names):
                try:
                    report['ap/{:s}'.format(label_name)] = result['ap'][l]
                except IndexError:
                    report['ap/{:s}'.format(label_name)] = np.nan

        observation = {}
        with reporter.report_scope(observation):
            reporter.report(report, target)
        return observation 
开发者ID:chainer,项目名称:chainercv,代码行数:43,代码来源:instance_segmentation_voc_evaluator.py

示例13: test_progress_hook

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def test_progress_hook(self):
        iterator = SerialIterator(self.dataset, 2, repeat=False)

        in_values, out_values, rest_values = apply_to_iterator(
            self.func, iterator,
            hook=ProgressHook(n_total=len(self.dataset)))

        # consume all data
        for _ in in_values[0]:
            pass 
开发者ID:chainer,项目名称:chainercv,代码行数:12,代码来源:test_progress_hook.py

示例14: test_progress_hook_with_infinite_iterator

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def test_progress_hook_with_infinite_iterator(self):
        iterator = SerialIterator(self.dataset, 2)

        in_values, out_values, rest_values = apply_to_iterator(
            self.func, iterator, hook=ProgressHook())

        for _ in range(10):
            next(in_values[0]) 
开发者ID:chainer,项目名称:chainercv,代码行数:10,代码来源:test_progress_hook.py

示例15: _check_apply_to_iterator

# 需要导入模块: from chainercv import utils [as 别名]
# 或者: from chainercv.utils import apply_to_iterator [as 别名]
def _check_apply_to_iterator(self, comm=None):
        values = apply_to_iterator(
            self.func, self.iterator, n_input=self.n_input,
            hook=self.hook, comm=comm)

        if comm is not None and not comm.rank == 0:
            self.assertEqual(values, None)
            return

        in_values, out_values, rest_values = values

        self.assertEqual(len(in_values), self.n_input)
        for in_vals, in_vals_expect in \
                zip_longest(in_values, self.in_values_expect):
            for in_val, in_val_expect in zip_longest(in_vals, in_vals_expect):
                np.testing.assert_equal(in_val, in_val_expect)

        self.assertEqual(len(out_values), self.n_output)
        for out_vals in out_values:
            self.assertEqual(len(list(out_vals)), len(self.dataset))

        self.assertEqual(len(rest_values), self.n_rest)
        for rest_vals, rest_vals_expect in \
                zip_longest(rest_values, self.rest_values_expect):
            for rest_val, rest_val_expect in \
                    zip_longest(rest_vals, rest_vals_expect):
                if isinstance(rest_val_expect, np.ndarray):
                    np.testing.assert_equal(rest_val, rest_val_expect)
                else:
                    self.assertEqual(rest_val, rest_val_expect) 
开发者ID:chainer,项目名称:chainercv,代码行数:32,代码来源:test_apply_to_iterator.py


注:本文中的chainercv.utils.apply_to_iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。