简体   繁体   English

ImportError:无法从“keras.preprocessing.image”导入名称“img_to_array”

[英]ImportError: cannot import name 'img_to_array' from 'keras.preprocessing.image'

Im new here.我是新来的。 I have problem with this code,我对这段代码有疑问,

#Library
import numpy as np
import pickle
import cv2
from os import listdir
from sklearn.preprocessing import LabelBinarizer
from keras.models import Sequential
from keras.layers import BatchNormalization
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.layers.core import Activation, Flatten, Dropout, Dense
from keras import backend as K
from keras.preprocessing.image import ImageDataGenerator
from keras.optimizers import Adam
from keras.preprocessing import image
#from tensorflow.keras.preprocessing.image import img_to_array
from keras.preprocessing.image import img_to_array
from sklearn.preprocessing import MultiLabelBinarizer
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt

I got an error我有一个错误

在此处输入图像描述

this code is from github link此代码来自github 链接

Im using我在用着

  1. python 3.7.13 python 3.7.13
  2. tensorflow 2.9 tensorflow 2.9
  3. opencv 4.5.5 opencv 4.5.5
  4. keras 2.9.0 keras 2.9.0

In Keras Documentation V2.9.0 ,Keras 文档 V2.9.0中,

In tf version 2.9.0 the img_to_array moved to utlistf 版本 2.9.0 中,img_to_array 移至 utlis

Insted of,安装,

from keras.preprocessing.image import img_to_array

Try this,尝试这个,

from tensorflow.keras.utils import img_to_array

现在是 2022.07.20 我的方法是:试试 from keras.utils.image_utils import img_to_array 就可以了!

Insted of,安装,

from keras.preprocessing.image import img_to_array从 keras.preprocessing.image 导入 img_to_array

Try:-尝试:-

from keras_preprocessing.image import img_to_array从 keras_preprocessing.image 导入 img_to_array

note: underscore (_) instead of dot (.)注意:下划线 (_) 而不是点 (.)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 keras.preprocessing.image import img_to_array ImportError: cannot import name 'img_to_array' from 'keras.preprocessing.image - from keras.preprocessing.image import img_to_array ImportError: cannot import name 'img_to_array' from 'keras.preprocessing.image 无法从“keras.preprocessing.image”导入名称“load_img” - cannot import name 'load_img' from 'keras.preprocessing.image' AttributeError: 模块 'keras.preprocessing.image' 没有属性 'img_to_array' - AttributeError: module 'keras.preprocessing.image' has no attribute 'img_to_array' ImportError:无法从“keras.preprocessing”导入名称“load_img” - ImportError: cannot import name 'load_img' from 'keras.preprocessing' 导入错误:无法从“keras.preprocessing”导入名称“image_dataset_from_directory” - ImportError: cannot import name 'image_dataset_from_directory' from 'keras.preprocessing' 导入错误:无法从“tensorflow.keras.preprocessing”(未知位置)导入名称“image_dataset_from_directory” - ImportError: cannot import name 'image_dataset_from_directory' from 'tensorflow.keras.preprocessing' (unknown location) 无法从keras.preprocessing.image导入apply_transform - Can't import apply_transform from keras.preprocessing.image load_img , keras.preprocessing.image ,TypeError: an integer is required (got type str) - load_img , keras.preprocessing.image ,TypeError: an integer is required (got type str) 如何解决? AttributeError: 模块 'keras.preprocessing.image' 没有属性 'load_img' - HOW TO FIX IT? AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img' ImportError:无法从“tensorflow”导入名称“keras” - ImportError: cannot import name 'keras' from 'tensorflow'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM