之前好几年的编程,遇到各种奇怪的报错,有的解决了有的没有,现在都忘了,我非常痛心。所以从现在(2023.05.10)开始对以后遇到的报错进行记录。
- 1.RuntimeError: Trying to backward through the graph a second time (or directly access saved variables after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved variables after calling backward.
- 2.File "D:\Projects\Flow\Flow_Forecast\venv\lib\site-packages\psycopg2\__init__.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError
- 3.TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64……
- 4.numpy.core._exceptions._ArrayMemoryError: Unable to allocate 3.99 MiB for an array with shape (39, 13410) and data type object
- 5.ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
- 6.You are trying to merge on datetime64[ns] and object columns. If you wish to proceed you should use pd.concat
- 7.can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, int64, int32, int16, int8, uint8, and bool.
- 8.only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
- 9.OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized
- 10.Out of range float values are not JSON compliant
- 11._pickle.PicklingError: Could not pickle the task to send it to the workers.
1.RuntimeError: Trying to backward through the graph a second time (or directly access saved variables after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved variables after calling backward.
解决方法:网上较多的是针对一个网络有多个输出分别进行梯度下降的情况,我遇到的则是Softmax和Parameter同时在一条语句中使用时报错,解决方法是去掉Softmax
2.File “D:\Projects\Flow\Flow_Forecast\venv\lib\site-packages\psycopg2_init_.py”, line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError
解决方法:这是一个很笼统的报错,以至于我没看出来。后来发现是字母大小写的问题,postgresql使用python新建表单和数据库时大写字母被强制转为小写,但在读取数据库和表的时候却分大小写,所以这边初始化报错了。建议postgresql中的名字都用小写。
3.TypeError: can’t convert np.ndarray of type numpy.object_. The only supported types are: float64……
解决方法:强制类型转换 x.astype(None),变更为普通数组
4.numpy.core._exceptions._ArrayMemoryError: Unable to allocate 3.99 MiB for an array with shape (39, 13410) and data type object
解决方法:这是读取数据内存溢出的问题。重跑模型或者优化内存配置。
5.ufunc ‘isnan’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’
解决方法:np.nan(a)中的a的类型有问题,修改为np.nan(a.astype(None))即可。
6.You are trying to merge on datetime64[ns] and object columns. If you wish to proceed you should use pd.concat
解决方法:这是在两个dateframe进行merge的时候出现的问题,需要将左右两个df的合并项格式进行统一。我这边报错是表1中的时间列为datetime64,表2中的时间列为object。
7.can’t convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, int64, int32, int16, int8, uint8, and bool.
解决方法:有变量x是object类型的,需要强制转换x.astype(float)
8.only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices
解决方法:索引必须为整数,将index强制转换为int
9.OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized
解决方法:libiomp5md.dll重复, 可参考这边。我用的方法一。
10.Out of range float values are not JSON compliant
解决方法:json 字典中存在不是数的内容,改一下就行
11._pickle.PicklingError: Could not pickle the task to send it to the workers.
python中多进程在切换系统时出现报错,主要由于Parallel的默认参数在部分系统不适用,重新指定一个参数即可。
解决方法:
joblib.Parallel(self.n_jobs) ——> joblib.Parallel(self.n_jobs, backend=“threading”)