module 'keras.backend' has no attribute 'unique_object_name' - python

This is the error I can't figure out.
module 'keras.backend' has no attribute 'unique_object_name'
This is what I'm importing:
import cv2
import os
from keras.models import load_model
import numpy as np
from pygame import mixer
import time
I get the error when I try and run this line:
model = load_model('C:/Users/Henry/Downloads/Drowsiness detection/Drowsiness detection/models/cnnCat2.h5')

Method keras.models.load_model() probably worked properly before Keras become part of Tensorflow.
If you are using newer version of tf you should call this to load model:
tf.keras.models.load_model()

Related

Couldn't find a pure Python 3 wheel for 'tensorflow'. You can use `micropip.install(..., keep_going=True)` to get a list of all packages

I want to use tensorflow in pyscript but it always throws this error. Please help me out.
<py-env>
- numpy
- tensorflow
- nltk
</py-env>
<body>
<py-script>
import random
import json
import pickle
import numpy as np
import nltk
from nltk.stem import WordNetLemmatizer
intents = json.loads(open("./intents.json").read())
import tensorflow as tf
keras = tf.keras
from keras.models import load_model
//further code..
</py-script>
PyScript can't run anything that has a C component to be compiled. That's why the error refers to a "pure Python" wheel. Bottom line, you can't use tensorflow in a browser.

No module named 'augmentations'?

I'm getting this error. It doesn't seem to find the augmentations module. I'm trying to use basicsr for model training.I already tried to install the augmentation module, albumentation, but it doesn't work.
Can someone help me and explain how to solve this?
How it's being imported:
import os.path
import random
import numpy as np
import cv2
import torch
import torch.utils.data as data
import data.util as util
import sys
sys.path.append('../codes/scripts')
sys.path.append('../codes/data')
**import augmentations # Here shows the module import error**
As it is being used below:
# Random Crop (reduce computing cost and adjust images to correct size first)
if img_HR.shape[0] > HR_size or img_HR.shape[1] > HR_size:
#Here the scale should be in respect to the images, not to the training scale (in case they are being scaled on the fly)
scaleor = img_HR.shape[0]//img_LR.shape[0]
img_HR, img_LR = augmentations.random_crop_pairs(img_HR, img_LR, HR_size, scaleor)
Console error:
File "D:\basicsrtrainmodel\BasicSR\codes\data\LRHROTF_dataset.py", line 12, in <module>
import augmentations
ModuleNotFoundError: No module named 'augmentations'
Someone help me please?

Calling librosa.grifflim returns an attribute error

In the following code I'm getting errors when trying to call librosa.grifflim, telling me the attribute does not exist.
import os
from matplotlib import pyplot as plt
import librosa
import librosa.display
import IPython.display as ipd
import numpy as np
import cv2
S = cv2.imread('spectrograms/CantinaBand60.wav10.jpg')
D = librosa.amplitude_to_db(np.abs(S), ref=np.max)
signal = librosa.griffinlim(D)
sf.write('test.wav', signal, 352000)
I've upgraded librosa, and I still encounter the error. The documentation page for this function no longer seems to exist either. I've also tried import just that module using librosa.griffinlim but it continues to tell me this module doesn't exist. Was this function removed during a recent version? If so, is there another function I can use to apply the griffin lim algorithm?
librosa.griffinlim was introduced in librosa 0.7.0. So you need to have that version or later. You can check this using the following code.
import librosa; print(librosa.__version__)

ImportError: cannot import name 'set_random_seed' from 'tensorflow' (C:\Users\polon\Anaconda3\lib\site-packages\tensorflow\__init__.py)

Good day,
Here is the error. Can somebody help how can i solve it?
ImportError Traceback (most recent call last)
<ipython-input-18-c29f17706012> in <module>
7 import numpy as np
8 import numpy.random as nr
----> 9 from tensorflow import set_random_seed
10 import matplotlib.pyplot as plt
11 get_ipython().run_line_magic('matplotlib', 'inline')
ImportError: cannot import name 'set_random_seed' from 'tensorflow' (C:\Users\polon\Anaconda3\lib\site-packages\tensorflow\__init__.py)
Looked for similar problems on Stack, but nothing worked for me.
In Tensoflow2 there is no need to perform
from tensorflow import set_random_seed
in order to run
set_random_seed(x)
(as it was in older version)
Only have to run
import tensorflow
tensorflow.random.set_seed(x)
Thanks to #David Buck
I too faced same error but instead of
from tensorflow import set_random_seed, I've used
import tensorflow as tf
tf.random.set_seed()
And it worked I think that method is useful for version 1 and the above snippet is useful for version 2
This code works for me:
from numpy.random import seed
seed(1)
from tensorflow import random
random.set_seed(1)
I got the same result of my neural network model every time.
TensorFlow API has been updated from set_random_seed() to set_seed()
You can use the following code :
from tensorflow.random import set_seed
Reference Link :
TensorFlow Random Seed
you can also try the following import statement
from tensorflow.python.framework.random_seed import set_random_seed
You want to use the random seed number.
You can try with this
import tensorflow as tf
tf.set_random_seed(1234)

Tensorflow Module Import error: AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn_cell'

When attempting to pass my RNN call, I call tf.nn.rnn_cell and I receive the following error:
AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn_cell'
Which is odd, because I'm sure I imported everything correctly:
from __future__ import print_function, division
from tensorflow.contrib import rnn
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
But looking at the docs, things have moved around between tensorflow versions.
what would you all recommend to fix this??
Line, I'm getting the error against:
state_per_layer_list = tf.unstack(init_state, axis=0)
rnn_tuple_state = tuple(
[tf.nn.rnn_cell.LSTMStateTuple(state_per_layer_list[idx][0], state_per_layer_list[idx][1])
for idx in range(num_layers)]
)
Specifically:
tf.nn.rnn_cell
I'm using anaconda 3 to manage all of this so, the dependancies should all be taken care of. I have already tried working around a damn rank/shape error with Tensor shapes which took ages to resolve.
Cheers in advance.
Replace tf.nn.rnn_cell with tf.contrib.rnn
Since version 1.0, rnn implemented as part of the contrib module.
More information can be found here
https://www.tensorflow.org/api_guides/python/contrib.rnn

Categories