from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import os
import pprint
import numpy as np
import torch
import torch.backends.cudnn as cudnn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
import torchvision.transforms
import torch.multiprocessing
from tqdm import tqdm
import matplotlib.pyplot as plt
tensorA=np.fromfile("tensorA.bin", dtype=np.float32)
print(tensorA.size)
125440
tensorB=np.fromfile("tensorB.bin", dtype=np.float32)
print(tensorB.size)
65856
tensorA_OG=np.fromfile("tensorA_official.bin", dtype=np.float32)
print(tensorA_OG.size)
tensorB_OG=np.fromfile("tensorB_official.bin", dtype=np.float32)
print(tensorB_OG.size)
125440 65856
# compare results
np.testing.assert_allclose(tensorA, tensorA_OG, rtol=1e-1, atol=1e-1)
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-14-679a4741e8c0> in async-def-wrapper() [... skipping hidden 2 frame] AssertionError: Not equal to tolerance rtol=0.1, atol=0.1 Mismatched elements: 267 / 125440 (0.213%) Max absolute difference: 0.39660645 Max relative difference: 16434.35 x: array([-4.642487e-03, -1.664162e-04, 1.788139e-07, ..., 2.694130e-04, -8.463860e-06, -2.479553e-04], dtype=float32) y: array([-4.287720e-03, -1.881123e-04, 1.055002e-05, ..., 1.398325e-04, -2.145767e-06, 7.539988e-05], dtype=float32)
np.testing.assert_allclose(tensorB, tensorB_OG, rtol=1e-1, atol=1e-1)
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-13-f7258296b3ca> in <module> ----> 1 np.testing.assert_allclose(tensorB, tensorB_OG, rtol=1e-1, atol=1e-1) [... skipping hidden 2 frame] AssertionError: Not equal to tolerance rtol=0.1, atol=0.1 Mismatched elements: 135 / 65856 (0.205%) Max absolute difference: 0.45117188 Max relative difference: 605.5 x: array([ 5.989075e-03, 1.056671e-03, 5.989075e-04, ..., -6.866455e-05, -3.280640e-04, 7.629395e-06], dtype=float32) y: array([ 5.855560e-03, 9.002686e-04, 4.653931e-04, ..., -7.629395e-05, -3.280640e-04, -1.144409e-04], dtype=float32)
np.testing.assert_allclose(tensorA, tensorA_OG, rtol=1e-05, atol=1e-09)
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-15-bbc2c1ecfaa5> in <module> ----> 1 np.testing.assert_allclose(tensorA, tensorA_OG, rtol=1e-05, atol=1e-09) [... skipping hidden 2 frame] AssertionError: Not equal to tolerance rtol=1e-05, atol=1e-09 Mismatched elements: 124481 / 125440 (99.2%) Max absolute difference: 0.39660645 Max relative difference: 16434.35 x: array([-4.642487e-03, -1.664162e-04, 1.788139e-07, ..., 2.694130e-04, -8.463860e-06, -2.479553e-04], dtype=float32) y: array([-4.287720e-03, -1.881123e-04, 1.055002e-05, ..., 1.398325e-04, -2.145767e-06, 7.539988e-05], dtype=float32)
np.testing.assert_allclose(tensorB, tensorB_OG, rtol=1e-05, atol=1e-1)
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-16-02518c9ed353> in <module> ----> 1 np.testing.assert_allclose(tensorB, tensorB_OG, rtol=1e-05, atol=1e-1) [... skipping hidden 2 frame] AssertionError: Not equal to tolerance rtol=1e-05, atol=0.1 Mismatched elements: 216 / 65856 (0.328%) Max absolute difference: 0.45117188 Max relative difference: 605.5 x: array([ 5.989075e-03, 1.056671e-03, 5.989075e-04, ..., -6.866455e-05, -3.280640e-04, 7.629395e-06], dtype=float32) y: array([ 5.855560e-03, 9.002686e-04, 4.653931e-04, ..., -7.629395e-05, -3.280640e-04, -1.144409e-04], dtype=float32)
print(tensorA)
[-4.6424866e-03 -1.6641617e-04 1.7881393e-07 ... 2.6941299e-04 -8.4638596e-06 -2.4795532e-04]
print(tensorA_OG)
[-4.2877197e-03 -1.8811226e-04 1.0550022e-05 ... 1.3983250e-04 -2.1457672e-06 7.5399876e-05]
print(tensorB)
[ 5.9890747e-03 1.0566711e-03 5.9890747e-04 ... -6.8664551e-05 -3.2806396e-04 7.6293945e-06]
print(tensorB_OG)
[ 5.8555603e-03 9.0026855e-04 4.6539307e-04 ... -7.6293945e-05 -3.2806396e-04 -1.1444092e-04]
tensorB2d=np.reshape(tensorB, (21, 56,56))
tensorB_OG2d_=np.reshape(tensorB_OG, (21, 56,56))
plt.imshow(tensorB2d[0], cmap='hot', interpolation='nearest')
plt.show()
plt.imshow(tensorB_OG2d_[0], cmap='hot', interpolation='nearest')
plt.show()