我最近注意到使用transform.resize会填满我的内存(就像很多: 23Go)。下面是我的函数
def resizePics(i):
target_size = 500
h, w = i.shape[0], i.shape[1]
if h > w: # crop to get a squared pic
crop_size = round((h - w)/2)
i = i[crop_size: h -crop_size, 0:w]
elif h < w:
crop_size = round((w - h)/2)
i = i[0:h, crop_size:w-crop_size]
i = transform.resize(i, (target_size,target_size), mode="constant", preserve_range=True) ##! HERE !##
return(i)
以及我在哪里调用它(data是一个pandas数据帧)
pool = ThreadPool(multiprocessing.cpu_count())
data["img"] = pool.map(resizePics, data["img"])
pool.close()
pool.close()
主要假设
我注意到在使用这个函数之后,我的矩阵的值发生了很大的变化(即使我使用了preserve_range=True)。这是在transform.resize之前:
data.head(5)
0 chest_xray/train/PNEUMONIA/person64_bacteria_3... pneumonia [[98, 100, 103, 104, 105, 107, 111, 114, 113, ... 504 144.0
1 chest_xray/train/NORMAL/NORMAL2-IM-1342-0001.jpeg normal [[0, 173, 163, 154, 144, 140, 132, 131, 129, 1... 1078 138.0
2 chest_xray/train/PNEUMONIA/person1441_bacteria... pneumonia [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... 1144 155.0
3 chest_xray/train/NORMAL/NORMAL2-IM-0576-0001.jpeg normal [[30, 31, 31, 28, 28, 30, 30, 30, 29, 27, 28, ... 1422 135.0
4 chest_xray/train/NORMAL/NORMAL2-IM-0660-0001.jpeg normal [[0, 2, 4, 3, 1, 1, 0, 0, 0, 1, 1, 3, 2, 0, 1,... 950 133.0
这是在以下内容之后:
data.head(5)
0 chest_xray/train/PNEUMONIA/person64_bacteria_3... pneumonia [[196.00400000000008, 197.000096, 197.02799999... 504 144.0
1 chest_xray/train/NORMAL/NORMAL2-IM-1342-0001.jpeg normal [[38.89042000000035, 38.15600000000006, 36.734... 1078 138.0
2 chest_xray/train/PNEUMONIA/person1441_bacteria... pneumonia [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... 1144 155.0
3 chest_xray/train/NORMAL/NORMAL2-IM-0576-0001.jpeg normal [[15.940252000000065, 17.550252000001198, 15.6... 1422 135.0
4 chest_xray/train/NORMAL/NORMAL2-IM-0660-0001.jpeg normal [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... 950 133.0
在我看来,对内存的影响与从int ->浮点数编码的像素有关。
there :有没有一种方法来调整transform.resize,以便
ints
后面的数字范围(比如,3个小数)
发布于 2018-06-09 20:14:25
对于绝大多数scikit-image
函数,内部表示是float
。特别是在需要某种平滑/反串扰/等的情况下。只有这样,我们才能保证输出尽可能精确和信息丰富。回答您的问题:
问题:有没有办法对transform.resize进行tweek,以便
ints
后面的数字范围(比如,3个小数)
对两个要点都是“负面”的:)。您应该手动将输出转换为所需的任何数据类型,例如使用{resize_output}.astype(np.uint8, casting='unsafe')
或numpy.around({resize_output}, decimals=3)
。
不过,我很想知道您的基准测试的详细信息。23 is是很大的容量。如果您可以准备一个显示高内存使用率的代码的最小示例,请将其发布到我们的GitHub错误跟踪器(https://github.com/scikit-image/scikit-image/issues)上。
https://stackoverflow.com/questions/50772362
复制相似问题