求问高手们这个报错怎么改?
我是python小白中的小白,最近学习关于青光眼视盘分割的深度学习,代码有报错,大致分析了一下错误代码段应该在这里:
for i in range(len(X_all)):
side = result_resolution[0]
if file_codes_all[i][-1] == ‘L’:
int(X_all[i]) = int(X_all[i][:, : int(orig_resolution[1]) // 2])
elif file_codes_all[i][-1] == ‘R’:
int(X_all[i]) = int(X_all[i][:, orig_resolution[1] // 2:])
if return_disc:
int(disc_all[i]) = disc_all[i][:, :orig_resolution[1] // 2]
if return_cup:
int(cup_all[i]) = cup_all[i][:, :orig_resolution[1] // 2]
else:
raise imh.ImLibException(‘image {} has no L/R characteristic’.format(file_codes_all[i]))引用文本
报错内容是
int(X_all[i]) = int(X_all[i][:, : orig_resolution[1] // 2])
TypeError: slice indices must be integers or None or have an index method
我查了资料,大概意思是python3环境下默认float型计算,解决方案大致是用//代替/或者只用int强制类型转换,但我不会搞呀,求助大神指点。
整个完整的函数定义如下
def extract_RIM_ONE_v3(db_folder, expert=‘avg’, return_disc=True, return_cup=True):
“”"
Cropped (to optic disc region, and a little more by vertical axis) images
with polygonal optic disc segmentation. 1424 x 2144 original, 1424 x 1424 after post-processing.
Images are two-channel (stereo) — caught from 2 angles.
But segmentation is given for only one view (see L/R letter in file name for clarification).
So only one view of two is chosen.
Accepted values for
expert
: 1, 2, ‘avg’.
Required schema:
db_folder/
Healthy/
Stereo Images/
N-{}-[L,R].jpg (number is without leading zeros, from 1 to 92)
(image cannot be used as is. it is two-part image, divided by vertical border)
Expert1_masks/
N-{}-[L,R]-Cup-exp1.png (4 files for one image number and L/R characteristic)
N-{}-[L,R]-Cup-exp1.txt
N-{}-[L,R]-Disc-exp1.png
N-{}-[L,R]-Disc-exp1.txt
Expert2_masks/
N-{}-[L,R]-Cup-exp2.png (4 files for one image number and L/R characteristic)
N-{}-[L,R]-Cup-exp2.txt
N-{}-[L,R]-Disc-exp2.png
N-{}-[L,R]-Disc-exp2.txt
Average_masks/
N-{}-[L,R]-Cup-Avg.png (4 files for one image number and L/R characteristic)
N-{}-[L,R]-Cup-Avg.txt
N-{}-[L,R]-Disc-Avg.png
N-{}-[L,R]-Disc-Avg.txt
Glaucoma and suspects/
(...) (the same as for Healthy, but images start with G not N)
"""
orig_resolution = (1424, 2144)
result_resolution = (1424, 1424)
if expert == 1:
expert_folder = ‘Expert1_masks’
suffix = ‘exp1’
elif expert == 2:
expert_folder = ‘Expert2_masks’
suffix = ‘exp2’
elif expert == ‘avg’:
expert_folder = ‘Average_masks’
suffix = ‘Avg’
else:
raise imh.ImLibException(‘value for “expert” argument not understood’)
X_all, disc_all, cup_all, file_codes_all, is_ill = [], [], [], [], []
for pic_type in (‘Healthy’, ‘Glaucoma and suspects’):
X, file_names = imh.load_set(os.path.join(db_folder, pic_type, ‘Stereo Images’))
X_all.extend(X)
rel_file_names = [os.path.split(fn)[-1] for fn in file_names]
file_codes = [fn[:fn.rfind(’.’)] for fn in rel_file_names]
file_codes_all.extend(file_codes)
> for fc in file_codes:
if return_disc:
disc_segmn = imh.load_image(os.path.join(db_folder, pic_type, expert_folder,
'{}-Disc-{}.png'.format(fc, suffix)))
disc_all.append(disc_segmn)
if return_cup:
cup_segmn = imh.load_image(os.path.join(db_folder, pic_type, expert_folder,
'{}-Cup-{}.png'.format(fc, suffix)))
cup_all.append(cup_segmn)
is_ill.append(HEALTHY if pic_type == 'Healthy' else GLAUCOMA_OR_SUSPECT)
for i in range(len(X_all)):
side = result_resolution[0]
if file_codes_all[i][-1] == ‘L’:
int(X_all[i]) = int(X_all[i][:, : int(orig_resolution[1]) // 2])
elif file_codes_all[i][-1] == ‘R’:
int(X_all[i]) = int(X_all[i][:, orig_resolution[1] // 2:])
if return_disc:
int(disc_all[i]) = disc_all[i][:, :orig_resolution[1] // 2]
if return_cup:
int(cup_all[i]) = cup_all[i][:, :orig_resolution[1] // 2]
else:
raise imh.ImLibException(‘image {} has no L/R characteristic’.format(file_codes_all[i]))
X_all[i] = imh.resize_image_to_square(X_all[i], side, pad_cval=0)
if return_disc:
disc_all[i] = imh.resize_image_to_square(disc_all[i], side, pad_cval=0)
disc_all[i] = disc_all[i].reshape(disc_all[i].shape + (1,))
if return_cup:
cup_all[i] = imh.resize_image_to_square(cup_all[i], side, pad_cval=0)
cup_all[i] = cup_all[i].reshape(cup_all[i].shape + (1,))
if return_disc:
if return_cup:
return X_all, disc_all, cup_all, file_codes_all, is_ill
return X_all, disc_all, file_codes_all, is_ill
if return_cup:
return X_all, cup_all, file_codes_all, is_ill
return X_all, file_codes_all, is_ill