I need to reproduce results with AutoKeras for the same input and configurations: I tried the following at the beginning of my notebook but still didn't got the same results.
I am using Tensorflow 2.0.4 and AutoKeras 1.0.12
seed_value= 0
import os
os.environ['PYTHONHASHSEED']=str(seed_value)
os.environ['TF_CUDNN_DETERMINISTIC'] = str(seed_value)
import tensorflow as tf
tf.random.set_seed(seed_value)
from keras import backend as K
import autokeras as ak
import random
random.seed(seed_value)
import numpy as np
np.random.seed(seed_value)
Note:
I want to reproduce results at different times; i.e. to get the same result after closing the notebook, and run the code again .. not during the same session.
I guess, you need to seed the generators before each call you want to be reproducable. The best option is to make such a decorator (or a context manager):
import contextlib
#contextlib.contextmanager
def reproducable(seed_value=0):
import os
os.environ['PYTHONHASHSEED']=str(seed_value)
os.environ['TF_CUDNN_DETERMINISTIC'] = str(seed_value)
import tensorflow as tf
tf.random.set_seed(seed_value)
from keras import backend as K
import autokeras as ak
import random
random.seed(seed_value)
import numpy as np
np.random.seed(seed_value)
yield
#reproducable()
def main():
# ...put your code here...
UPD
Note: I want to reproduce results at different times; i.e. to get the same result after closing the notebook, and run the code again .. not during the same session.
and?
Related
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()
I am working on a small library and I need to know can I import modules like numpy, sklearn and etc. Using functions. For example:
def ml():
import numpy as np
import pandas as pd
x = np.array([1,2,647,345,3,7,3,8,36,64])
Is this possible ?
Simply can I import a module using a function and then use that later outside the function
The main idea is when the user calls the function ml he has all the modules related to machine learning imported and then he can use them. X = np.array was just kind of an example.
UPDATED
This should work
import importlib
def importmd(modulex):
return importlib.import_module(modulex) #Returning the module
np = importmd("numpy") #Same as import numpy as np
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__)
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)
I'm writing code in a Jupyter Notebook that involves cleaning and analyzing a large amount of consumer data. I'm trying to use dill to save the dataframes with thousands of rows so I don't have to run the code every time I want to make an adjustment, so dill seems like the perfect package to do so... Except I'm getting this error when attempting to pickle the notebook:
AttributeError: module 'dill' has no attribute 'dump_session'
Let me know if the program code is necessary - I don't think it should make a difference. The imports are:
import numpy as np
import pandas as pd
import dill
import scipy
from matplotlib import pyplot as plt
from __future__ import division
from collections import OrderedDict
from sklearn.cluster import KMeans
pd.options.display.max_columns = None
and when I run this code I get the error from above:
dill.dump_session('recengine.db')
Is there another package that's interfering with dill's use of pickle vs. cpickle?