[英]TypeError: slice indices must be integers or None or have an __index__ method (Google Colab)
I was trying to run the Step1_Data_RemoveNoise.ipynb notebook from microsoft/nestle-acne-assessment on Google Colab.我试图从 Google Colab 上的 microsoft/nestle-acne-assessment运行Step1_Data_RemoveNoise.ipynb笔记本。 When the image processing processed 100 images and above in the dataset, it started to throw an error TypeError: slice indices must be integers or None or have an __index__ method
.当图像处理处理数据集中 100 张及以上的图像时,它开始抛出错误TypeError: slice indices must be integers or None or have an __index__ method
。
The error output:错误输出:
No cheeks or forehead detected, output the original file levle1_128.jpg
Face not detected by landmarks model...
Left eye detected
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-93f89d71afa0> in <module>()
165 if forehead_max_y - forehead_min_y >= 0.7 * eyes1[0, 3]:
166 forehead_ok = True
--> 167 forehead_region = img[forehead_min_y:forehead_max_y, forehead_min_x: forehead_max_x, :]
168 forehead_region = cv2.cvtColor(forehead_region, cv2.COLOR_BGR2RGB)
169 forehead_file_name = join(croppedFaces_Dir, imageName+"_fh.jpg")
TypeError: slice indices must be integers or None or have an __index__ method
This is the levle1_128.jpg image.这是levle1_128.jpg图像。 The error appeared here.错误出现在这里。
this occurs when we use a non-integer value for slicing.In this phase of coding当我们使用非整数值进行切片时会发生这种情况。在这个编码阶段
########################
# Get the forehead patch
########################
[right_brow_min_x, left_brow_max_x] = \
[max(0, np.min(np.array(right_brow_landmarks[:,0]))), min(img_width, np.max(np.array(left_brow_landmarks[:,0])))]
brow_min_y = min(np.min(np.array(right_brow_landmarks[:,1])),np.min(np.array(left_brow_landmarks[:,1])))
forehead_x_min = right_brow_min_x # forehead starts at the left landmark of the right eye brow
forehead_x_max = left_brow_max_x
forehead_y_min = max(0, brow_min_y - forehead_height)
forehead_y_max = min(brow_min_y, forehead_y_min + forehead_height)
forehead_region = img[forehead_y_min:forehead_y_max, forehead_x_min:forehead_x_max, :]
forehead_file_name = join(croppedFaces_Dir, imageName+"_fh.jpg")
# BGR image needs to be converted to RGB before saving as image file
forehead_region = cv2.cvtColor(forehead_region, cv2.COLOR_BGR2RGB)
misc.imsave(forehead_file_name, forehead_region)
the line线
forehead_y_min = max(0, brow_min_y - forehead_height)
forehead_y_max = min(brow_min_y, forehead_y_min + forehead_height)
may produce a float value forehead_y_min
, while calculating your image size and shape.在计算图像大小和形状时,可能会产生一个浮点值forehead_y_min
。 I detected the place where you got an error.我检测到您出错的地方。
this solution MAY help you : making the size of the input image to standard-sized may avoid such errors.此解决方案可能会帮助您:将输入图像的大小设置为标准大小可以避免此类错误。 :) hope may help you :) :) 希望可以帮助你:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.