简体   繁体   English

导入错误:无法从“keras.preprocessing”导入名称“image_dataset_from_directory”

[英]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_directoryfrom 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.

相关问题 导入错误:无法从“tensorflow.keras.preprocessing”(未知位置)导入名称“image_dataset_from_directory” - ImportError: cannot import name 'image_dataset_from_directory' from 'tensorflow.keras.preprocessing' (unknown location) ImportError:无法从“keras.preprocessing”导入名称“load_img” - ImportError: cannot import name 'load_img' from 'keras.preprocessing' ImportError 与 keras.preprocessing - ImportError with keras.preprocessing ImportError:无法从“keras.preprocessing.image”导入名称“img_to_array” - ImportError: cannot import name 'img_to_array' from 'keras.preprocessing.image' Keras:`image_dataset_from_directory` 中标签的一次性使用 - Keras: one-hot for labels in `image_dataset_from_directory` 如何将 keras image_dataset_from_directory 与自定义结构一起使用? - How to use keras image_dataset_from_directory with custom structures? 是否可以从 image_dataset_from_directory 获取图像名称? - is it possible to get image name from image_dataset_from_directory? 如何查看keras的image_dataset_from_directory function生成的数据集? - How to view the dataset generated by the image_dataset_from_directory function of keras? 如何从 Keras 中的 image_dataset_from_directory() 从 MapDataset 附加或获取文件名? - How to attach or get filenames from MapDataset from image_dataset_from_directory() in Keras? 将 tensorflow 数据集从 keras 拆分为训练集、测试集和验证集。预处理 API - Splitting a tensorflow dataset into training, test, and validation sets from keras.preprocessing API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM