AttributeError: in user code: File "<ipython-input-66-6d273dc751c7>", line 3, in load_image_train * img = read_jpg(img_path) File "<ipython-input-102-e29e7c2bee65>", line 4, in read_jpg * img = tf.image.decode_jpg(img,channels=3) AttributeError: module 'tensorflow._api.v2.image' has no attribute 'decode_jpg'
时间: 2024-04-10 12:33:31 浏览: 15
这个错误是因为在 TensorFlow 2.x 中,`tf.image` 模块不再包含 `decode_jpg` 方法。取而代之的是 `tf.image.decode_image` 方法,它可以解码多种图像格式,包括 JPEG。您可以将 `decode_jpg` 方法替换为 `decode_image` 方法来解决此问题。
请修改代码中的以下行:
```python
img = tf.image.decode_jpg(img, channels=3)
```
替换为:
```python
img = tf.image.decode_image(img, channels=3)
```
这样应该可以解决 `AttributeError` 异常。
相关问题
AttributeError Traceback (most recent call last) <ipython-input-18-484e38e099dc> in <module>() 1 from sklearn import preprocessing ----> 2 minmiax_scale = preprocessing.MinMaxSacler((0,1)) AttributeError: module 'sklearn.preprocessing' has no attribute 'MinMaxSacler'
您好!根据错误信息,看起来是由于您拼写错误导致的。正确的类名应该是 `MinMaxScaler` 而不是 `MinMaxSacler`。请修改代码如下:
```python
from sklearn import preprocessing
minmax_scale = preprocessing.MinMaxScaler((0,1))
```
请注意修改后的代码中的 `MinMaxScaler` 拼写正确。如果还有其他问题,请随时提问。
Exception in Tkinter callback Traceback (most recent call last): File "E:\Anaconda3\lib\tkinter\__init__.py", line 1892, in __call__ return self.func(*args) File "<ipython-input-9-c46edc755222>", line 185, in <lambda> command=lambda key=key: analyze_and_show_result(key)) File "<ipython-input-9-c46edc755222>", line 166, in analyze_and_show_result result = model_analysis(model_name) File "<ipython-input-9-c46edc755222>", line 69, in model_analysis X = data.iloc[:, :-1] AttributeError: 'numpy.ndarray' object has no attribute 'iloc'
这个错误是由于你在代码中使用了一个 numpy 数组,而这个数组没有 iloc 属性。iloc 是 pandas.DataFrame 和 pandas.Series 所具有的方法,用于选取数据集中某些行和列。你需要将 numpy 数组转换成 pandas.DataFrame 或者 pandas.Series 才能使用 iloc 方法。