python3 keras import error with both tensorflow and theano - python-3.x

With python3 (version 3.6.8) and keras
the simple script:
import keras
gives an error:
Using TensorFlow backend.
Ungültiger Maschinenbefehl (Speicherabzug geschrieben)
(in english it would be something like: "invalid machine command (memory image written)")
So I tried to use theano instead:
import os
os.environ['KERAS_BACKEND'] = 'theano'
from keras import backend as K
With python3 it shows this output:
Using Theano backend.
Ungültiger Maschinenbefehl (Speicherabzug geschrieben)
How could I get further information about the problem?

Try
from tensorflow import keras
If the problem persists, try going through the documentation on how to install and how to use it.
Keras - Tensorflow
Keras Overview - Tensorflow
Keras.io

Related

AttributeError: module 'tensorflow' has no attribute 'get_default_graph'. I am getting this error when adding a new layer to a model

ml = Sequential()
ml.add(LSTM(64,dropout=0.5, recurrent_dropout=0.5,return_sequences=True))
This is giving me a error: AttributeError: module 'tensorflow' has no attribute 'get_default_graph'.
ml is the name of the model. I am unable to add any layers to a model. Please help.
The dependencies that I am using are:
Tensorflow: 2.0.0-beta1
Keras: 2.2.4
Python: 3.7.3
Upgrade to latest Tensorflow version instead of Beta Version.And use the import functions as mentioned below.
To install:
pip install tensorflow==2.2.0
#OR
pip install --upgrade tensorflow
Importing:
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM
ml = Sequential()
ml.add(LSTM(64,dropout=0.5, recurrent_dropout=0.5,return_sequences=True))
Your code should work fine now.

Error when importing 'keras' from 'tensorflow'

I'm trying to import keras using TensorFlow 2.0 RC and using Python 3.6.3.
import tensorflow as tf
from tensorflow import keras
I'm getting an error when using the SPYDER IDE:
ImportError: cannot import name 'keras' from 'tensorflow'
I've tried searching on google for an answer but no avail. Any help would be appreciated :) !
From Keras repo.:
Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano.Before installing Keras, please install one of its backend engines: TensorFlow, Theano, or CNTK. We recommend the TensorFlow backend.
So Keras is a skin (an API). TensorFlow has decided to include this skin inside itself as tf.keras. Since Keras provides APIs that TensorFlow has already implemented (unless CNTK and Theano overtake TensorFlow which is unlikely).
So, we can use simply install keras by using pip
pip install keras
kerasis an additional package which uses tensorflow (or tensorflow-gpu) as backend. You have to install keras too
python -m pip install keras
Now you can use it
>>> import keras
Using TensorFlow backend.
>>> print(keras.__version__)
2.2.4
>>>
It seems to be kinda new that keras is delivered with tensorflow (or my information are old...). Anyway I tested your way and it works for me:
python -m pip install tensorflow==2.0RC
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> from tensorflow import keras
>>> print(keras.__version__)
2.2.4-tf
>>> print(tensorflow.__version__)
2.0.0-rc0
Have you tried try to upgrade / reinstall your packages?

import of keras and tensorflow seems to break pycharm

I'm facing a weird issue.
I'm working in Pycharm IDE and I want to use keras with tensorflow backend.
When I try to import keras or tensorflow pycharm process finished with exit code -1073741819 (0xC0000005).
For example
import tensorflow as tf
n_input = 2
print (n_input)
returns message described above without printing anything.
If i comment the tf import it works.
Keras and tensorflow are correctly installed under the python interpreter of my choice.
I'm on windows machine, Python 3.6.8
Thanks

Problems setting up FastAi working on Colab

I'm trying to work through a tutorial on CycleGANs using the Colab platform but I'm struggling to find a way through the 'simple' part of just importing libraries.
I'm just trying to import the following:
from fastai.conv_learner import *
from fastai.dataset import *
from cgan.options.train_options import *
from sklearn.model_selection import train_test_split
from cgan.options.train_options import TrainOptions
from cgan.data.data_loader import CreateDataLoader
from cgan.models.models import create_model
from cgan.util.visualizer import Visualizer
from google_images_download import google_images_download
I'm currently stuck with an error on the first line:
----> 7 class IntermediateLayerGetter(nn.ModuleDict):
8 """
9 Module wrapper that returns intermediate layers from a model
AttributeError: module 'torch.nn' has no attribute 'ModuleDict'
The code can be found online: https://colab.research.google.com/drive/1dMQWStzLfAHDTGuKaUNQn1aOBWeJw4FN
Did you check this issue it sorts partially the problem.
Afterthat I received and this error (Detected that PyTorch and torchvision were compiled with different CUDA versions. PyTorch has CUDA Version=9.0 and torchvision has CUDA Version=10.0. Please reinstall the torchvision that matches your PyTorch install.) and solve it with
pip install torch==1.0.1 -f https://download.pytorch.org/whl/cu100/stable
I hope it helps :)

keras import fails "no module named contrib.ctc"

On OSX El CApitan 10.11.6 I've installed theano & tensorflow fine. But the keras install is not happy as seen from the trace below. I've seen this reported on github issues but with no solution there, only a suggestion to post here on SO.
>>>import theano
>>>
>>> import tensorflow
>>>
>>> import keras
File "/Users/petercotton/anaconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 6, in <module>
import tensorflow.contrib.ctc as ctc
ImportError: No module named contrib.ctc`
Suggestions appreciated.
This is a problem with Keras, not TensorFlow and a known issue.
A workaround is mentioned here but that would mean that you have to modify Keras code (keras/backend/tensorflow_backend.py).
Luckily, it seems that this issue is fixed in the master branch of Keras.

Resources