如何使用Mac上安装的TensorFlow运行代码?

发布于 2025-02-11 05:53:34 字数 885 浏览 1 评论 0原文

我正在运行代码,并且有Mac。我正在尝试培训人工神经网络。我想使用Keras。

我编写了此代码:

有以下错误:


modulenotfounderror trackback(最近的最新通话) 输入[1],in<单元线:13>() 11来自Sklearn.Perprecorsing进口标准标准 12来自numpy import loadtxt ---> 13导入TensorFlow作为TF 14来自TensorFlow Import Keras 16 Start ='2017-06-26'ModulenotFoundError

:没有名为“ TensorFlow”的模块

,但我得到了以下内容,因此存在Tensoflow。我可以改变什么?我必须更改安装的版本吗?还是我们必须放一个图书馆?任何提示都将不胜感激

。 名称:TensorFlow 版本:0.12.0 摘要:TensorFlow有助于张量流动 主页:

你有一个主意吗?

代码:

import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential()
model.add(Dense(2, input_shape=(2,)))
model.add(Activation('sigmoid'))
model.add(Dense(1))
model.add(Activation('sigmoid')) 
model.compile(loss='mean_squared_error', optimizer='sgd', metrics=['accuracy'])```

I am running a code and I have MAC.I am trying to train an Artificial Neural Network. I thought to use keras.

I have written this code:

There is the following error:


ModuleNotFoundError Traceback (most recent call last)
Input In [1], in <cell line: 13>()
11 from sklearn.preprocessing import StandardScaler
12 from numpy import loadtxt
---> 13 import tensorflow as tf
14 from tensorflow import keras
16 start='2017-06-26'

ModuleNotFoundError: No module named 'tensorflow'

But I get the following, so tensoflow exists. What can I change? Do I have to change the version that is installed? Or do we have to put another library? Any hint will be appreciated....

pip show tensorflow
Name: tensorflow
Version: 0.12.0
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /opt/homebrew/lib/python3.9/site-packages
Requires: numpy, protobuf, six, wheel

Do you have an idea?

Code:

import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential()
model.add(Dense(2, input_shape=(2,)))
model.add(Activation('sigmoid'))
model.add(Dense(1))
model.add(Activation('sigmoid')) 
model.compile(loss='mean_squared_error', optimizer='sgd', metrics=['accuracy'])```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2025-02-18 05:53:34

您需要使用以下命令安装最新的稳定张量流版本

python3 -m venv ~/tensorflow-metal
source ~/tensorflow-metal/bin/activate
python -m pip install -U pip
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal

You need to install latest stable Tensorflow version using following commands

python3 -m venv ~/tensorflow-metal
source ~/tensorflow-metal/bin/activate
python -m pip install -U pip
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文