hog()得到了一个意外的关键字参数'visualize'

Sea*_*anJ 3 python scikit-image

我正在运行scikit-image Histogram of Gradients 示例

示例代码如下:

import matplotlib.pyplot as plt

from skimage.feature import hog
from skimage import data, color, exposure


image = color.rgb2gray(data.astronaut())

fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16),
                    cells_per_block=(1, 1), visualize=True)

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)

ax1.axis('off')
ax1.imshow(image, cmap=plt.cm.gray)
ax1.set_title('Input image')
ax1.set_adjustable('box-forced')

# Rescale histogram for better display
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 0.02))

ax2.axis('off')
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('Histogram of Oriented Gradients')
ax1.set_adjustable('box-forced')
plt.show()
Run Code Online (Sandbox Code Playgroud)

简而言之,它不起作用并报告以下错误:

    fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualize=True)
TypeError: hog() got an unexpected keyword argument 'visualize'
Run Code Online (Sandbox Code Playgroud)

我可以通过评论上面的部分来查看宇航员图像,这不是问题所在.有谁知道它失败的原因?

Lak*_*wal 6

这是一个非常小的错误,但关键字参数的拼写visualize错误.它应该是

fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16),
                cells_per_block=(1, 1), visualise=True)
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅此处

  • 文档没有错 - 它们只是用于不同版本的skimage而不是你正在使用的问题已经修复.该参数最初被命名为`visualise`,现在是`visualize`,但是接下来两个版本都接受了这两个版本,直到我们可以通过我们的标准弃用周期弃用`visualise`. (5认同)
  • 谢谢!sckit-image 网站是错误的。对于后代:https://web.archive.org/web/20171001204310/http://scikit-image.org/docs/dev/auto_examples/features_detection/plot_hog.html (2认同)