[英]ImportError: cannot import name 'image_dataset_from_directory' from 'keras.preprocessing'
I used anaconda in ubuntu-20.04 operating systems.我在 ubuntu-20.04 操作系统中使用了 anaconda。
Keras version is: 2.4.3
Keras 版本为:2.4.3
Tensorflow version: 2.2.0
Tensorflow 版本:2.2.0
I imported below packages,我导入了以下包,
import os
import keras
import numpy as np
import tensorflow as tf
from keras.models import Model
import matplotlib.pyplot as plt
from keras.optimizers import Adam
from keras.applications import MobileNet
from sklearn.metrics import confusion_matrix
from keras.layers.core import Dense, Activation
from keras.metrics import categorical_crossentropy
from sklearn.model_selection import train_test_split
from keras.preprocessing.image import ImageDataGenerator
from keras.applications.mobilenet import preprocess_input
from keras.preprocessing import image_dataset_from_directory //Here I faced error
Error is also below, please concern here,错误也在下面,请关注这里,
ImportError Traceback (most recent call last)
<ipython-input-8-477695c122c5> in <module>
13 from keras.preprocessing.image import ImageDataGenerator
14 from keras.applications.mobilenet import preprocess_input
---> 15 from keras.preprocessing import image_dataset_from_directory
ImportError: cannot import name 'image_dataset_from_directory' from 'keras.preprocessing' (/home/imdadul/anaconda3/lib/python3.8/site-packages/keras/preprocessing/__init__.py)
Note: Please concern my problem and help me for solving this error.注意:请关注我的问题并帮助我解决此错误。
First off, I cannot find any keras
implementation of image_dataset_from_directory
, but instead only the tensorflow.keras
implementation, imported by writing: from tensorflow.keras.preprocessing import image_dataset_from_directory
.首先,我找不到
image_dataset_from_directory
任何keras
实现,而只有tensorflow.keras
实现,通过写入from tensorflow.keras.preprocessing import image_dataset_from_directory
: from tensorflow.keras.preprocessing import image_dataset_from_directory
。 In the keras
-documentation , they refer to use tensorflow.keras
as well.在
keras
-documentation 中,他们也提到使用tensorflow.keras
。
However, since you are using Tensorflow 2.2.0
, I am afraid that will not be possible either, as explained here .但是,由于您使用的是
Tensorflow 2.2.0
,恐怕这也不可能,如解释here 。 I would recommend installing Tensorflow 2.3.0
, and it should work.我建议安装
Tensorflow 2.3.0
,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.