解决cannot set WRITEABLE flag to True of this array
在复现tensflow完成视频的行人流量密度检测的过程中,遇到了这个问题。现在总结一下,给遇到同样问题的伙伴们提供个想法。
问题原因:
numpy版本与pytables的最新版本不兼容,有说要numpy降版本,但是降版本会非常麻烦,而且会涉及到不兼容等更多问题。
解决方法参考原地址:
https://www.jianshu.com/p/2bfa498e3d67
原本的代码:
np.copyto(image, np.array(image_pil))
报错: assignment destination is read-only
查了查说是要把image_pil
属性手动修改为可写
修改如下:
imgg=image
imgg.flags.writeable=True
img=np.array(image_pil)
img.flags.writeable=True
np.copyto(imgg, img))
然后就出现了标题遇到的问题,加入这一行处理即可imgg = np.require(imgg, dtype='f4', requirements=['O', 'W'])
imgg=image
imgg = np.require(imgg, dtype='f4', requirements=['O', 'W'])
imgg.flags.writeable=True
img=np.array(image_pil)
img.flags.writeable=True
np.copyto(imgg, img)