【问题标题】:UFuncTypeError dtype u32UFuncTypeError 数据类型 u32
【发布时间】:2020-04-24 20:08:51
【问题描述】:

结节识别模型

此模型将肺部扫描(3D 图像)中的一个小体积(块)作为输入,并将该块分为两类:

Class 0 : Chunk does not contain a nodule
Class 1 : Chunk contains a nodule

我在这部分遇到了这个错误:UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype(' dtype('

def get_validation_batch(validation_x_ids,validation_y,batch_number): num_images = len(validation_x_ids)

    count = 0
    start_index = batch_number * FLAGS.batch_size
    end_index = start_index + FLAGS.batch_size
    end_index = num_images if end_index > num_images else end_index
    real_batch_size = end_index - start_index

    validation_x = np.ndarray([real_batch_size, FLAGS.chunk_size, FLAGS.chunk_size, FLAGS.chunk_size, 1], dtype=np.float32)

    for chunk_id in validation_x_ids[start_index : end_index]:
        chunk = np.load(DATA_PATH + chunk_id + '_X.npy').astype(np.float32, copy=False)
        validation_x[count, :, :, :, :] = img_to_rgb(chunk)
        count = count + 1

    return validation_x, validation_y[start_index : end_index]

【问题讨论】:

    标签: python-3.x deep-learning bigdata conv-neural-network


    【解决方案1】:

    错误是由于np.load(...) 语句中字符串连接的数据类型不匹配,其中chund_id 是从np.ndarray() 获得的整数,而'_X.npy' 是字符串。

    因此,将chunk = np.load(DATA_PATH + chunk_id + '_X.npy').astype(np.float32, copy=False) 行替换为以下行:

    chunk = np.load(DATA_PATH + str(chunk_id) + '_X.npy').astype(np.float32, copy=False)
    

    在添加其他字符串之前先将 chunk_idstr() 进行类型转换。

    参考资料:

    【讨论】:

    • OSError: [Errno 36] 文件名太长: '/content/luna_preprocessing_2/[[[[0.]\n [0.]\n [0.]\n ...\ n [0.]\n [0.]\n [0.]]\n\n [[0.]\n [0.]\n [0.]\n ...\n [0.] \n
    • 似乎 chunk_id 不是整数,可能是对象。你能打印type(chunk_id) 并检查它的确切类型吗?
    • chunk_id的类型是
    猜你喜欢
    • 2021-07-28
    • 2020-12-17
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 2023-04-03
    • 2021-11-23
    • 2018-07-25
    • 2021-03-11
    相关资源
    最近更新 更多