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
Related
Would you help me to achieve reproducible results with Tensorflow 1.15 without restarting Python kernel. And why the output results in TF 2.0 and TF 1.5 are different with absolutely identical parameters and dataset? Is it possible to achieve identical output?
More details:
I tried to interpret model results in TF 2.0 by:
import shap
background = df3.iloc[np.random.choice(df3.shape[0], 100, replace=False)]
explainer = shap.DeepExplainer(model, background)
I recieved an error:
`get_session` is not available when using TensorFlow 2.0.`get_session` is not available when using TensorFlow 2.0.
According to the SO topic, I tried to setup TF 2.0 compatibility with TF 1 by using in the front of my code:
import tensorflow.compat.v1 as tf
But the error appeared again.
Following advice by many users, I downgraded TF2 to TF 1.15 it solved the problem, and shap module interprets the results but:
1) to make results reproducible now I have to change tf.random.set_seed(7) on tf.random.set_random_seed(7) and restart the Python kernel every time! In TF2 I didn't have to restart the kernel.
2) prediction results has been changed, especially, Economical efficiency (that is, TF1.5. wrongly classifies more important samples than TF2.0).
TF 2:
Accuracy: 94.95%, Economical efficiency = 64%
TF 1:
Accuracy: 94.85%, Economical efficiency = 56%
The code of the model is here
First, results differ from each other not only in TF1 and TF2 versions, but also in TF2.0 and TF2.2 versions. Probably, it depends on diffenent internal parameters in the packages.
Second, TensorFlow2 works with DeepExplainer in the following versions:
import tensorflow
import pandas as pd
import keras
import xgboost
import numpy
import shap
print(tensorflow.__version__)
print(pd.__version__)
print(keras.__version__)
print(xgboost.__version__)
print(numpy.__version__)
print(shap.__version__)
output:
2.2.0
0.24.2
2.3.1
0.90
1.17.5
0.35.0
But you will face some difficulties in updating the libraries.
In Python 3.5, running TF2.2, you will face the error 'DLL load failed: The specified module could not be found'.
It 100% can be solved by installing newer C++ package. See this:https://github.com/tensorflow/tensorflow/issues/22794#issuecomment-573297027
Link to download the package:https://support.microsoft.com/ru-ru/help/2977003/the-latest-supported-visual-c-downloads
In Python 3.7 you will not find the shap 0.35.0 version with whl extention. Only tar.gz extension which gives the error: "Install visual c++ package". But installation doesn't help.
Then download shap 0.35.0 for Python 3.7 here: https://anaconda.org/conda-forge/shap/files. Run Anaconda shell. Type: conda install -c conda-forge C:\shap-0.35.0-py37h3bbf574_0.tar.bz2.
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
I'm trying to use keras on a jupyter lab using tensorflow (python 3.6) through miniconda.
Jupyter lab keeps give me a restarting error(Kernel Restarting The kernel for Desktop/Transfer/Untitled.ipynb appears to have died. It will restart automatically.)
Because the kernel restarting error is evident whenever I try to import keras. The code I used is (from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array, array_to_img).
Code
Therefore, I assume that there is a problem between keras and kernel even though I already installed ipykernel in my tensorflow directory ((tensorflow) C:\Users\user).
Pip_list
Still couldn't figure out this kernel and keras problem :(.
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 :)
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.