代码之家  ›  专栏  ›  技术社区  ›  zar3bski

skipage transform.resize对RAM的负面影响

  •  0
  • zar3bski  · 技术社区  · 7 年前

    我最近注意到 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)
    

    我调用它的地方(数据是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
    

    在我看来,对RAM的影响与从int->浮点编码的像素有关。

    [ 问题 ]:是否有方法将transform.resize设置为

    • 坚持ints
    • 限制(例如,3位小数)后的数字范围
    1 回复  |  直到 7 年前
        1
  •  0
  •   soupault    7 年前

    对于绝大多数 scikit-image 内部表示的功能是 float . 尤其是在需要某种平滑/抗艾莉莎因等的地方。只有这样我们才能保证输出尽可能精确和信息丰富。回答你的问题:

    [问题]:是否有方法来tweek transform.resize以便

    • 坚持ints
    • 限制(例如,3位小数)后的数字范围

    两个要点都是“否定的”:)。您应该手动将输出转换为所需的任何数据类型,例如。, {resize_output}.astype(np.uint8, casting='unsafe') numpy.around({resize_output}, decimals=3) .

    不过,我很想知道你的基准测试的细节。23GB是很多。如果您可以准备一个显示高内存使用率的代码的最小示例,请将其发布到我们的GitHub bugtracker上( https://github.com/scikit-image/scikit-image/issues ).