我想要查看.pth特征文件里面的内容,结果输出的数据都是科学计数法表示的,如下
具体数字多大看不出来,加上下面一句:
np.set_printoptions(formatter={'float_kind':'{:f}'.format})
输出结果如下:
代码
import numpy as np
import torch
import sys
import os
class Logger(object):
def __init__(self, filename="Default.log"):
self.terminal = sys.stdout
self.log = open(filename, "a")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
pass
np.set_printoptions(threshold=np.inf)
sys.stdout = Logger('c.txt')
state_dict = torch.load("data/rcnn_feature/9.pth") # 这个是特征文件,注意路径
s = state_dict["spatial_feature"] # s是numpy类型的
# print(state_dict["image_feature"].shape)
np.set_printoptions(formatter={'float_kind':'{:f}'.format})
print(s)
print('---------------------------------------')