GoodWin/Deep-Multi-scale
0
1# -*- coding: utf-8 -*-2# File : unittest.py3# Author : Jiayuan Mao4# Email : maojiayuan@gmail.com5# Date : 27/01/20186#7# This file is part of Synchronized-BatchNorm-PyTorch.8# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch9# Distributed under MIT License.10 11import unittest12import torch13 14 15class TorchTestCase(unittest.TestCase):16 def assertTensorClose(self, x, y):17 adiff = float((x - y).abs().max())18 if (y == 0).all():19 rdiff = 'NaN'20 else:21 rdiff = float((adiff / y).abs().max())22 23 message = (24 'Tensor close check failed\n'25 'adiff={}\n'26 'rdiff={}\n'27 ).format(adiff, rdiff)28 self.assertTrue(torch.allclose(x, y), message)29 30 