I'm trying to import img_to_array even though all packages are there. This error still appears:
Traceback (most recent call last):
File "c:\Users\Usuario\Downloads\keras-api\keras-main.py", line 11, in <module> from keras.preprocessing.image import img_to_array
ImportError: cannot import name 'img_to_array' from 'keras.preprocessing.image'
This is how I am calling the packages from the keras package.
from keras.preprocessing.image import img_to_array
On the other hand, this is what I'm trying to do with the code.
image = img_to_array(image)
However, I cannot even continue because I'm not able to import img_to_array
but this is how you import img_to_array if you have installed the keras package via e.g. pip install keras
from keras.utils import img_to_array
img_to_array
check if the keras version is the correct one:
Keras Installation Guide
Related
Trying to run some machine learning examples so am importing some packages
sklearn version 0.22.1
tensorflow version 2.3.0
keras version 2.3.0
in the following way:
import os
import sys
import math
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlip.pyplot as plt
I am getting the import error:
ImportError: cannot import name 'Sequence'
Full traceback:
File "C:\Anaconda\lib\site-packages\keras\__init__.py", line 12, in <module>
from . import callbacks
File "C:\Anaconda\lib\site-packages\keras\callbacks\__init__.py", line 3, in <module>
from .callbacks import Callback
File "C:\Anaconda\lib\site-packages\keras\callbacks\callbacks.py", line 23, in <module>
from ..engine.training_utils import standardize_input_data
File "C:\Anaconda\lib\site-packages\keras\engine\training_utils.py", line 18, in <module>
from ..utils import Sequence
ImportError: cannot import name 'Sequence'
I have looked on line for help trying a few different tensorflow and keras versions. I have also tried:
import tensorflow.keras as keras
and import tensorflow.keras.utils import Sequence
without success
I'm learning ObjectDetection from this website
I have installed ImageAI,Tensorflow and Keras.
Then when I run this in python
from imageai.Detection import ObjectDetection
I got
Traceback (most recent call last):
File "", line 1, in
File "/home/carl/python-environments/env/lib/python3.9/site-packages/imageai/Detection/init.py", line 17, in
from imageai.Detection.YOLOv3.models import yolo_main, tiny_yolo_main
File "/home/carl/python-environments/env/lib/python3.9/site-packages/imageai/Detection/YOLOv3/models.py", line 8, in
from keras.layers.normalization import BatchNormalization
ImportError: cannot import name 'BatchNormalization' from 'keras.layers.normalization' (/home/carl/python-environments/env/lib/python3.9/site-packages/keras/layers/normalization/init.py)
Already tried:
from keras.layers.normalization.batch_normalization import BatchNormalization
from tensorflow.keras.layers import BatchNormalization
But still gave me the same error.
Tensorflow v2.8.0 support tf.keras.layers.BatchNormalization()
import tensorflow as tf
tf.keras.layers.BatchNormalization()
I am using anaconda env.
Python 3.7
keras : 2.3.1
tensorflow: 2.1.0
when i want to use CenterCrop and Rescaling modules, pycharm gives me error.
from tensorflow.keras.layers.experimental.preprocessing import CenterCrop
from tensorflow.keras.layers.experimental.preprocessing import Rescaling
error messages is:
D:\NewAnaconda\envs\Tensor_Turkcell\python.exe "C:/Users/Burak Ekincioğlu/Dekstop/TENSORFLOW/tensor_intro.py"
Traceback (most recent call last):
File "C:/Users/Burak Ekincioğlu/Dekstop/TENSORFLOW/tensor_intro.py", line 5, in <module>
from tensorflow.keras.layers.experimental.preprocessing import CenterCrop
ImportError: cannot import name 'CenterCrop' from 'tensorflow.keras.layers.experimental.preprocessing' (D:\NewAnaconda\envs\Tensor_Turkcell\lib\site-packages\tensorflow_core\python\keras\api\_v2\keras\layers\experimental\preprocessing\__init__.py)
I've tried the import with tensorflow 2.1.0 (keras 2.2.4 by default) and it gave me the same error you are encountering.
Using Tensorflow 2.2.0 with keras 2.3.0 works fine.
So you just need to upgrade tensorflow.
I'm using Tensorflow v2.1.0 which is compiled from source. How can I import any function from conv_utils module? E.g. convert_data_format(), conv_output_length(), normalize_tuple(), etc.
I wanna create my own convolution/pooling layer. "Everything" almost looks different when I wanna migrate from import keras to from tensorflow import keras.
This is what I did
> python -c "from tensorflow.keras.utils import conv_utils"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name 'conv_utils' from 'tensorflow.keras.utils' ...
Thank you.
Try this:
from tensorflow.python.keras.utils import conv_utils
This is the new way to import conv_utils in Tensorflow 2.1.0:
import tensorflow.keras.utils as conv_utils
import keras
from keras.models import Model
from keras.layers import Dense, Dropout, LSTM, Input, Activation
from keras import optimizers
import numpy as np
np.random.seed(4)
from tensorflow import set_random_seed
set_random_seed(4)
from util import csv_to_dataset, history_points
Using TensorFlow 2.0 as backend and got following errors.
Traceback (most recent call last):
File "C:/Users/sander/PycharmProjects/autotrader/basic_model.py", line 7, in <module>
from tensorflow import set_random_seed
ImportError: cannot import name 'set_random_seed' from 'tensorflow' (C:\Users\sander\venv\lib\site-packages\tensorflow\__init__.py)
What does this error mean?
set_random_seed is a function not a module, have you tried following steps?
In tf 1.x, do it as this:
import tensorflow as tf
tf.set_random_seed(4)
In tf 2.0, do this as this:
import tensorflow as tf
tf.compat.v1.set_random_seed(4)