Ejemplo n.º 1
0
 def test_AverageMeter_str_smoke(self):
     for show_local_avg in (True, False):
         meter = optim.AverageMeter("test_average_meter",
                                    show_local_avg=show_local_avg)
         self.assertIsInstance(str(meter), str)
         meter.update(0.0)
         self.assertIsInstance(str(meter), str)
Ejemplo n.º 2
0
    def test_AverageMeter_update_tensor(self):
        actual_meter = optim.AverageMeter("actual_meter")
        desired_meter = optim.AverageMeter("desired_meter")

        torch.manual_seed(0)
        vals = torch.rand(10)

        actual_meter.update(vals)
        desired_meter.update(vals.tolist())

        for attr in (
                "count",
                "last_val",
                "global_sum",
                "global_min",
                "global_max",
                "global_avg",
                "local_avg",
        ):
            actual = getattr(actual_meter, attr)
            desired = getattr(desired_meter, attr)
            self.assertAlmostEqual(actual, desired)
Ejemplo n.º 3
0
    def test_ProgressMeter_update(self):
        meters = [optim.AverageMeter(str(idx)) for idx in range(3)]
        progress_meter = optim.ProgressMeter(1, *meters)

        vals = [float(val) for val in range(len(meters))]
        progress_meter.update(
            **{meter.name: val
               for meter, val in zip(meters, vals)})

        actual = progress_meter.count
        desired = 1
        self.assertEqual(actual, desired)

        for meter, val in zip(meters, vals):
            actual = meter.last_val
            desired = val
            self.assertFloatAlmostEqual(actual, desired)
Ejemplo n.º 4
0
def test_ProgressMeter_update():
    meters = [optim.AverageMeter(str(idx)) for idx in range(3)]
    progress_meter = optim.ProgressMeter(1, *meters)

    vals = [float(val) for val in range(len(meters))]
    progress_meter.update(
        **{meter.name: val
           for meter, val in zip(meters, vals)})

    actual = progress_meter.count
    desired = 1
    assert actual == desired

    for meter, val in zip(meters, vals):
        actual = meter.last_val
        desired = val
        assert actual == pytest.approx(desired)