报错”解决方法"/>
Mac M1 由于arm导致“tensorflow 报错”解决方法
Mac m1 由于arm导致“tensorflow 报错”解决方法
- 问题描述
- 导致问题的原因
- 问题解决
问题描述
最近发现之前在Mac m1安装的tensorflow无法使用了,这里的无法使用不是指无法import之类的错误,而是使用相关模块时代码报错,报错如下(小伙伴们可以参考):
2021-09-03 17:05:21.327506: I tensorflow/compiler/mlir/mlir_graph_optimization_pass:116] None of the MLIR optimization passes are enabled (registered 2)
2021-09-03 17:05:21.327724: W tensorflow/core/platform/profile_utils/cpu_utils:126] Failed to get CPU frequency: 0 Hz
2021-09-03 17:05:21.328620: F tensorflow/core/grappler/costs/op_level_cost_estimator:710] Check failed: 0 < gflops (0 vs. 0)type: "CPU"
model: "0"
num_cores: 8
environment {key: "cpu_instruction_set"value: "ARM NEON"
}
environment {key: "eigen"value: "3.3.90"
}
l1_cache_size: 16384
l2_cache_size: 524288
l3_cache_size: 524288
memory_size: 268435456
进程已结束,退出代码为 134 (interrupted by signal 6: SIGABRT)
导致问题的原因
简而言之,就是安装了不正确的tensorflow版本~~
问题解决
- First of all, 你需要python版本为 3.8(经靓仔尝试,3.9对本方法似乎不太行)
- 在github上下载这个bash脚本:github链接
或者在下面直接复制,保存为.sh文件:
#!/bin/bashset -eVERSION=0.1alpha3
INSTALLER_PACKAGE=tensorflow_macos-$VERSION.tar.gz
INSTALLER_PATH=$VERSION/$INSTALLER_PACKAGE
INSTALLER_SCRIPT=install_venv.shecho# Check to make sure we're good to go.
if [[ $(uname) != Darwin ]] || [[ $(sw_vers -productName) != macOS ]] || [[ $(sw_vers -productVersion) != "11."* ]] ; then echo "ERROR: TensorFlow with ML Compute acceleration is only available on macOS 11.0 and later." exit 1
fi# This
echo "Installation script for pre-release tensorflow_macos $VERSION. Please visit "
echo "for instructions and license information."
echo
echo "This script will download tensorflow_macos $VERSION and needed binary dependencies, then install them into a new "
echo "or existing Python 3.8 virtual environment."# Make sure the user knows what's going on.
read -p 'Continue [y/N]? ' if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
echoecho "Downloading installer."
tmp_dir=$(mktemp -d)pushd $tmp_dircurl -LO $INSTALLER_PATH echo "Extracting installer."
tar xf $INSTALLER_PACKAGEcd tensorflow_macos function graceful_error () { echo echo "Error running installation script with default options. Please fix the above errors and proceed by running "echo echo " $PWD/$INSTALLER_SCRIPT --prompt"echo echoexit 1
}bash ./$INSTALLER_SCRIPT --prompt || graceful_error popd
rm -rf $tmp_dir
- 关于怎么使用bash脚本,请大家参考这个链接哦
怎样在macOS上运行Shell或.sh脚本 - 运行完bash脚本就可以了哦,中间运行脚本需要涉及两个操作:输入y、输入虚拟环境的路径
- 现在可以进行测试一下哦
import tensorflow as tf
import time
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([tf.keras.layers.Flatten(input_shape=(28, 28)),tf.keras.layers.Dense(128, activation='relu'),tf.keras.layers.Dropout(0.2),tf.keras.layers.Dense(10, activation='softmax')
])
modelpile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
start = time.time()
model.fit(x_train, y_train, epochs=5)
end = time.time()
model.evaluate(x_test, y_test)
print(end - start)
希望可以解决大家的问题,嘻嘻嘻!
更多推荐
Mac M1 由于arm导致“tensorflow 报错”解决方法
发布评论