Python Keras后端json被定义为tensorflow,但Keras仍然可以';找不到张量流
我已将keras的json文件更改为:Python Keras后端json被定义为tensorflow,但Keras仍然可以';找不到张量流,python,machine-learning,tensorflow,theano,keras,Python,Machine Learning,Tensorflow,Theano,Keras,我已将keras的json文件更改为: { "image_dim_ordering": "tf", "epsilon": 1e-07, "floatx": "float32", "backend": "tensorflow" } 但当我为神经网络运行以下简单的Keras教程时: from keras.models import Sequential from keras.layers import Dense, Dropout, Activation fr
{
"image_dim_ordering": "tf",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "tensorflow"
}
但当我为神经网络运行以下简单的Keras教程时:
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
model = Sequential()
# Dense(64) is a fully-connected layer with 64 hidden units.
# in the first layer, you must specify the expected input data shape:
# here, 20-dimensional vectors.
model.add(Dense(64, input_dim=20, init='uniform'))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
model.add(Dense(64, init='uniform'))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
model.add(Dense(10, init='uniform'))
model.add(Activation('softmax'))
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
optimizer=sgd,
metrics=['accuracy'])
model.fit(X_train, y_train,
nb_epoch=20,
batch_size=16)
score = model.evaluate(X_test, y_test, batch_size=16)
摘自:
我仍然得到以下错误:
Using TensorFlow backend.
Traceback (most recent call last):
File "./keras_test", line 3, in <module>
from keras.models import Sequential
File "/usr/local/lib/python2.7/dist-packages/keras/__init__.py", line 2, in <module>
from . import backend
File "/usr/local/lib/python2.7/dist-packages/keras/backend/__init__.py", line 67, in <module>
from .tensorflow_backend import *
File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1, in <module>
import tensorflow as tf
ImportError: No module named tensorflow
如果我再次运行它,我会得到以下输出:
Requirement already satisfied (use --upgrade to upgrade): keras in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): theano in /usr/local/lib/python2.7/dist-packages (from keras)
Requirement already satisfied (use --upgrade to upgrade): pyyaml in /usr/local/lib/python2.7/dist-packages (from keras)
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from keras)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.1 in /usr/local/lib/python2.7/dist-packages (from theano->keras)
Requirement already satisfied (use --upgrade to upgrade): scipy>=0.11 in /usr/local/lib/python2.7/dist-packages (from theano->keras)
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
此外,我100%确信我的Tensorflow安装工作正常,因为我已经为它运行了(并编写了)一些GPU Cuda示例
谢谢 我想你忘了最明显的一件事,TensorFlow没有安装,也不是Keras依赖项。我建议您使用以下设备安装TensorFlow:
pip install --user tensorflow
这将在我们的用户文件夹(~/.local)中安装TensorFlow,并且不需要root权限。您可以安装TensorFlow和keras的所有依赖项,如下所示: 此设置适用于Ubuntu 14.04服务器
# Pick up some TF dependencies
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
git \
cmake \
libfreetype6-dev \
libpng12-dev \
libzmq3-dev \
pkg-config \
python \
python-dev \
rsync \
software-properties-common \
unzip \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
curl -O https://bootstrap.pypa.io/get-pip.py && \
python get-pip.py && \
rm get-pip.py
pip --no-cache-dir install --upgrade ipython && \
pip --no-cache-dir install \
ipykernel \
jupyter \
matplotlib \
numpy \
scipy \
sklearn \
pandas \
Pillow \
&& \
python -m ipykernel.kernelspec
# Install TensorFlow CPU version from central repo
pip --no-cache-dir install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp27-none-linux_x86_64.whl
# h5py is optional dependency for keras
apt-get update && apt-get install -y libhdf5-dev libhdf5-serial-dev
pip install keras h5py
如果你仍然有环境问题,我建议你使用这个。这使我们能够独立于本地python工作,我发现本地python对于在任何其他系统上复制环境都非常有用。您可能还发现Datmo转换有助于实现这一点
免责声明:我在一家名为的公司工作,我们正在通过简化机器学习工作流程建立一个开发人员社区您是否在conda环境中运行keras?当您启动python然后“导入tensorflow”时会发生什么?当我启动python并使用“导入tensorflow”时,我没有收到任何错误消息。一切都很完美。我不是在conda环境下运行,一切都在我的主pc/系统上。话虽如此,当我在virtualenv中做所有事情时,一切似乎都很好(这并不是说这有助于解决我在这里发布的问题),但我至少可以开始与keras合作了/我相信我已经安装了TensorFlow。:/因为我已经在我的电脑上安装并使用了tensorflow gpu,所以我知道它就在那里functional@pche8701当然可以,但问题中没有任何证据表明安装了tensorflow。请提供一些。
# Pick up some TF dependencies
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
git \
cmake \
libfreetype6-dev \
libpng12-dev \
libzmq3-dev \
pkg-config \
python \
python-dev \
rsync \
software-properties-common \
unzip \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
curl -O https://bootstrap.pypa.io/get-pip.py && \
python get-pip.py && \
rm get-pip.py
pip --no-cache-dir install --upgrade ipython && \
pip --no-cache-dir install \
ipykernel \
jupyter \
matplotlib \
numpy \
scipy \
sklearn \
pandas \
Pillow \
&& \
python -m ipykernel.kernelspec
# Install TensorFlow CPU version from central repo
pip --no-cache-dir install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.1-cp27-none-linux_x86_64.whl
# h5py is optional dependency for keras
apt-get update && apt-get install -y libhdf5-dev libhdf5-serial-dev
pip install keras h5py