其他分享
首页 > 其他分享> > VisibleDeprecationWarning , Creating an ndarray from ragged nested sequences... 警告怎么办

VisibleDeprecationWarning , Creating an ndarray from ragged nested sequences... 警告怎么办

作者:互联网

我不是完美主义,但是至少,我在做实验的时候不能容忍有 warning 的出现。

今天使用 tensorflow.keras.datasets中的 imdb 数据集,使用 imdb.load_data() 方法导入数据的时候,报出一个警告,VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

经过查阅,得知这是因为创建 numpy包中 ndarray 类对象时,设若 np.array( some_object),如果传入的参数 some_object 是个 ragged 的,或者维度不整齐,或者每维元素数量不固定的,那么就会报出这个 warning。

这不是自己写的代码有问题,而是人家写好的代码模块有问题(现在能 被 numpy 兼容,以后会被弃置的)。所以可以修改人家写好的 imdb.load_data 的代码。

方法。

先 import warings, 然后 warnings.simplefilter("error"),使得 warning 不会通过检查,报出warning位置,找到了关于创建 ndarray 的代码,这就在imdb.load_data 方法内部

 

 

一共两处,

分别做如下修改:

 

 

然后就没有 warning 了。

---------------------------------------------------------------------------------------

Conclusion

---------------------------------------------------------------------------------

哇,第一次改人家的库,虽然并不是底层的库,也是很爽。我 cao 勇 的(ww腔)~~

Above all, 浪费了很多的时间,只为了不见个warning,感觉很亏。

还是要抓主要矛盾,下次一定。 :)

标签:load,VisibleDeprecationWarning,Creating,...,object,warning,imdb,data,ndarray
来源: https://www.cnblogs.com/yinshuo666/p/15014968.html