在udacity中自驾https://github.com/udacity/self-driving-car/tree/master/vehicle-detection/u-net方法get_mask_seg(img,bb_boxes_f)给出切片索引必须是整数或无,或者具有索引方法
<ipython-input-58-b0cc385c742b> in <module>()
2
3 training_gen = generate_train_batch(df_vehicles,10)
----> 4 batch_img,batch_mask = next(training_gen)
<ipython-input-55-1399e4d6a92a> in generate_train_batch(data, batch_size)
12 scale_range=50
13 )
---> 14 img_mask = get_mask_seg(img,bb_boxes)
15 batch_images[i_batch] = img
16 batch_masks[i_batch] =img_mask
<ipython-input-51-b5ad142378f0> in get_mask_seg(img, bb_boxes_f)
8 bb_box_i = [bb_boxes_f.iloc[i]['xmin'],bb_boxes_f.iloc[i]['ymin'],
9 bb_boxes_f.iloc[i]['xmax'],bb_boxes_f.iloc[i]['ymax']]
---> 10 img_mask[bb_box_i[1]:bb_box_i[3],bb_box_i[0]:bb_box_i[2]]= 1
11 img_mask = np.reshape(img_mask,(np.shape(img_mask)[0],np.shape(img_mask)[1],1))
12 return img_mask
TypeError: slice indices must be integers or None or have an __index__ method
答案 0 :(得分:0)
此代码效果更好
img_mask[int(bb_box_i[1]):int(bb_box_i[3]),int(bb_box_i[0]):int(bb_box_i[2])]= 1