I am developing a fairly big model and I need to use tf.RunOptions or other debuggers to slim a little my code because I'm getting OOM errors with really small batch sizes. But I get a segfault after using tf.RunOptions.
I don't believe it's a model problem, because also the following code will give problems (while the same code without the runopt is working):
import tensorflow as tf
import tensorflow.keras.models as mm
import tensorflow.keras.layers as ll
import numpy as np
model = mm.Sequential([
ll.Dense(27,input_shape=(1,)),
ll.Activation('relu'),
ll.Dense(27),
ll.Activation('softmax')
])
runopt = tf.RunOptions(report_tensor_allocations_upon_oom = True)
model.compile(optimizer='sgd',
loss='mean_squared_error',
metrics=['accuracy'],
options=runopt)
a = np.zeros(27)*10
model.fit(a,a,epochs=10)
Got the same error on Linux 18.04 (tensorflow-gpu installed with pip, tf version 1.13.1, python version 3.6.7, CUDA 9.1.85, GeForce GTX 980 4GB) and on macOS 10.12.6 (tensorflow-cpu installed with pip, tf version 1.13.1, python version 3.7.2)
To use tf.RunOptions, you have to use also tf.RunMetadata()!
This fixed this issue:
import tensorflow as tf
import tensorflow.keras.models as mm
import tensorflow.keras.layers as ll
import numpy as np
model = mm.Sequential([
ll.Dense(27,input_shape=(1,)),
ll.Activation('relu'),
ll.Dense(27),
ll.Activation('softmax')
])
runopt = tf.RunOptions(report_tensor_allocations_upon_oom = True)
runmeta = tf.RunMetadata()
model.compile(optimizer='sgd',
loss='mean_squared_error',
metrics=['accuracy'],
options=runopt,
run_metadata=runmeta)
Related
I'm using tensorflow 1.15.0 in docker container and have issue in importing keras sub-modules.
from tensorflow import keras
import tensorflow.keras.backend as K
from tensorflow.keras.optimizers import Adam, SGD
Both backend and Adam, SGD cannot be imported.
Any solutions for this ?
I know that is too late, but I confronted the same issue and I just wanted to share the solution that worked successfully for me
try to use this instead :
import tensorflow as tf
import keras
from keras import backend as k
at least you can use Adam() like this :
tf.keras.optimizers.Adam()
the same goes for SGD() :
tf.keras.optimizers.SGD()
I just start learning tensorflow with Tutorials of Tensorflow Core.
import os
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_datasets as tfds
train_data, validation_data, test_data = tfds.load(name='imdb_reviews', split=('train[:60%]', 'train[60%:]', 'test'), as_supervised=True)
then I got error like this.
error messages
Some blog says this Error can be resolved by installing tensorflow-gpu.
But in my case, that dosen't work.
How can I fix this error?
(win10, anaconda. conda ver. 4.9.2., windows terminal, anaconda prompt)
After re-installation of Anaconda and Tensorflow issue was resolved.
import os
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_datasets as tfds
train_data, validation_data, test_data = tfds.load(name='imdb_reviews', split=('train[:60%]', 'train[60%:]', 'test'), as_supervised=True)
I am trying to use a pre-trained model in Tensorflow. I am using the following code:
import tensorflow as tf
from tensorflow import keras
from keras.applications import mobilenet_v2
I get the following error:
ModuleNotFoundError: No module named 'keras'
However, the following codes do work:
from tensorflow.keras.applications import mobilenet_v2
OR
from keras_applications import mobilenet_v2
The 2 methods mentioned above work but the 1st one doesn't. Why does this happen?
I've solved this problem by downgrading tensorflow to version 2.0 using this command:
pip install tensorflow==2.0
I hope it helps you.
i tried this code
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
import tensorflow as tf
mnist = tf.keras.datasets.mnist
print("gud to go")
(training, newtraining)= mnist.load_data()
and this error showed
https://hastebin.com/eridajexev.sql
i have tried upgrading it and tensorflow but it shows error ,may be post how to do that ,that may work
help please?
edit:
im using version 1.9.0 of tensorflow
edit2 :
i used pip3 install --upgrade tensorflow==1.10.0 and still no and note that ,im using python3
So I am new to machine learning and was trying out the TensorFlow Linear Model Tutorial given here:
https://www.tensorflow.org/tutorials/wide
I literally just downloaded their tutorial and tried to run it in my computer but I got the error:
AttributeError: module 'tensorflow' has no attribute 'feature_column'
I searched online and got to know that this can happen on older versions of tensorflow, but I am running the latest version: 1.3.0
So why am I getting this error and how to fix it?
Tensorflow 1.3 should support feature_column well. You might accidentally used an old version. Try the following code to verify your version:
import tensorflow as tf
print(tf.__version__)
print(dir(tf.feature_column))
If you're importing Tensorflow in a project that uses Keras, import Keras modules first, then Tensorflow. That solved the problem for me.
Do this: (notice the order)
from keras.backend.tensorflow_backend import set_session
from keras.models import Sequential
from keras import applications
import tensorflow as tf
Do not do this:
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
from keras.models import Sequential
from keras import applications
Upgrading your tensorflow might help.
pip install --upgrade tensorflow
I faced a similar error while running a session using the Tensorflow 2.0 beta. I used the following form for running a session:
import tensorflow as tf
constant = tf.constant([[1, 2, 3],[4, 5, 6],[7, 8, 9]])
with tf.compat.v1.Session() as sess:
print(sess.run(constant))
instead of:
import tensorflow as tf
constant = tf.constant([[1, 2, 3],[4, 5, 6],[7, 8, 9]])
with tf.Session() as sess:
print(sess.run(constant))
Also,
tf.compat.v1.Session()
is backward compatible. You might face a similar error when using other functions in Tensorflow 2.0 beta like print, get_variable, etc. Use a similar form as shown above in the example.