简体   繁体   中英

How can I run the code with tensorflow which is installed on MAC?

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: opensource@google.com 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'])```

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM