module 'theano' has no attribute 'compile' - python

I just try to import the packages first on Jupyter Notebook
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt
but I got this error
AttributeError: module 'theano' has no attribute 'compile'

Related

Importing Adam and ImageDataGenerator on google colab failed

I'm implementing a UNet neural network but I'm having some issues while importing libraries. I found a solution for a couple of them, but I still have a problem with these two imports:
from tensorflow.keras.optimizers import Adam
#Import "tensorflow.keras.optimizers" could not be resolved(reportMissingImports)
from tensorflow.keras.preprocessing.image import ImageDataGenerator
#Import "tensorflow.keras.preprocessing.image" could not be resolved(reportMissingImports)
I've already imported:
import tensorflow as tf
from tensorflow import keras
from keras import layers
import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
import numpy as np
Any idea? I've tried to change but it still raises an error.

ModuleNotFoundError: No module named 'tensorflow' on Jupyter Notebook

when I try to import keras on a Jupyter notebook I receive this error message: ModuleNotFoundError: No module named 'tensorflow'.
I need to use keras to build an LSTM model fora project and am a beginner in python so I don't know how to get around this error. I have tried to install tenserflow and keras into an environment on anaconda but I receive the same error. For reference, I am using a Mac.
My code:
#Import libraries used
import math
import pandas as pd
import pandas_datareader.data as web
import datetime as dt
import numpy as np
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense, LSTM
Any help would be greatly appreciated!

AttributeError: module 'keras.engine.base_layer' has no attribute 'BaseRandomLayer'

Context - I was getting errors when saving/loading EfficientNetB7 and one of the articles I saw suggested installing tf-nightly. Well that really blew things up in my Google Colab! I uninstalled tf-nightly, restarted my runtime, and now when I go to run my import cell, I get the errors below.
I reinstalled tensorflow 2.6.0.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-25-5d853ee59f92> in <module>()
11 import tensorflow as tf
12 from tensorflow import keras
---> 13 from tensorflow.keras import Model
14 from tensorflow.keras.models import Sequential
15 from tensorflow.keras.utils import to_categorical
11 frames
/usr/local/lib/python3.7/dist-packages/keras/layers/core/dropout.py in <module>()
24
25 #keras_export('keras.layers.Dropout')
---> 26 class Dropout(base_layer.BaseRandomLayer):
27 """Applies Dropout to the input.
28
AttributeError: module 'keras.engine.base_layer' has no attribute 'BaseRandomLayer'
I also had an issue with this import before:
from tensorflow.keras import backend as keras
Here are all my imports:
import os
import glob
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.transform import resize
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.losses import categorical_crossentropy
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout, BatchNormalization
from tensorflow.keras.callbacks import ModelCheckpoint, LearningRateScheduler
from datetime import datetime
from sklearn.metrics import confusion_matrix, accuracy_score, f1_score, precision_score, recall_score
import skimage.io as io
import skimage.transform as trans
from tensorflow.keras import models
from tensorflow.keras import layers
from tensorflow.keras import optimizers
from tensorflow.keras.models import *
from tensorflow.keras.layers import *
from tensorflow.keras.optimizers import *
from tensorflow.keras.callbacks import ModelCheckpoint, LearningRateScheduler
from tensorflow.keras import backend as keras
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from keras_preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers.schedules import ExponentialDecay
import scipy.misc as sc
import h5py
from sklearn.semi_supervised import LabelSpreading
from sklearn.model_selection import GridSearchCV
from tensorflow.keras.applications import * #Efficient Net included here
import shutil
from sklearn import model_selection
from tqdm import tqdm
# import warnings
# warnings.filterwarnings("ignore", category=DeprecationWarning)
Try rolling back the python version to 3.6. If you are using Anaconda run
conda install python=3.6
Then install keras
pip install keras==2.0.8
Worked for me in Ubuntu.
I was able to get rid of the issue after installing tensorflow==2.8.0.

I m getting error 'unresolved import keras.layers.experimental' in visual studio

I m getting error 'unresolved import keras.layers.experimental' in visual studio
my python import list is like this
import sys
import math
import pandas_datareader as web
import numpy as np
import pandas.testing as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
i think problem is becouse windows cant using these libs but im not sure

module 'pandas' has no attribute 'DataFrame' when using alibi package in Python

I'm hoping someone can help me. When I run the following setup I get the error below. It seems like the alibi package is causing it. The other posts related to this problem are either because of case sensitive spellings of 'DataFrame' or .py filenames.
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR) # suppress deprecation messages
from tensorflow.keras import backend as K
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.models import Model, load_model
from tensorflow.keras.utils import to_categorical
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import os
from sklearn.datasets import load_boston
from alibi.explainers import CounterFactualProto
AttributeError: module 'pandas' has no attribute 'DataFrame'

Categories

Resources