python 为什么从karas.utils导入np_utils时会出现ImportError异常

fykwrbwg  于 2023-09-29  发布在  Python
关注(0)|答案(1)|浏览(115)
from tensorflow import keras
import numpy as np
import pickle
import cv2, os
from glob import glob
from keras import optimizers
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import Flatten
from tensorflow.keras.layers import Conv2D, MaxPooling2D
from keras.utils import np_utils
from keras.callbacks import ModelCheckpoint
from keras import backend as K

我正在尝试导入以下模块和包。但我面对这个错误,说:

Traceback (most recent call last):
  File "c:\Users\KUNDANA\Desktop\rama\DSA- Python\trails.py", line 13, in <module>
    from keras.utils import np_utils
ImportError: cannot import name 'np_utils' from 'keras.utils' (C:\Users\KUNDANA\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\utils\__init__.py)
kokeuurv

kokeuurv1#

看起来你想提前对数据的目标进行一次热编码。请使用代码:

from keras.utils import to_categorical

而不是这一行:

from keras.utils import np_utils

问题就解决了。

相关问题