我正在尝试使用来自 tensorflow keras 的 Sequential 模型。当我执行以下语句时:
model.fit(x_train, y_train, epochs=20, verbose=True, validation_data=(x_dev, y_dev), batch_size=10)
我收到以下错误:
I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
W tensorflow/core/platform/profile_utils/cpu_utils.cc:126] Failed to get CPU frequency: 0 Hz
F tensorflow/core/grappler/costs/op_level_cost_estimator.cc:710] Check failed: 0 < gflops (0 vs. 0)type: "CPU"
我无法理解如何修复它。任何人都可以帮助我。
从 github 上的 this issue,我了解到 device.frequency() 返回 0 可能是因为 NominalCPUFrequency() 返回 1。 然而,这些信息对我来说似乎太抽象了,我无法理解。
答案 0 :(得分:2)
前两个不用担心。
第三个有问题。您安装了不正确的 TensorFlow 版本。使用支持 Mac M1 芯片的芯片。
运行以下 bash 脚本下载并安装 TensorFlow。
#!/bin/bash
set -e
VERSION=0.1alpha3
INSTALLER_PACKAGE=tensorflow_macos-$VERSION.tar.gz
INSTALLER_PATH=https://github.com/apple/tensorflow_macos/releases/download/v$VERSION/$INSTALLER_PACKAGE
INSTALLER_SCRIPT=install_venv.sh
echo
# 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 https://github.com/apple/tensorflow_macos "
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
echo
echo "Downloading installer."
tmp_dir=$(mktemp -d)
pushd $tmp_dir
curl -LO $INSTALLER_PATH
echo "Extracting installer."
tar xf $INSTALLER_PACKAGE
cd 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
echo
exit 1
}
bash ./$INSTALLER_SCRIPT --prompt || graceful_error
popd
rm -rf $tmp_dir
答案 1 :(得分:2)
我在 macOS 11.4 上做了如下操作(即使参考说“操作系统要求 macOS 12.0+”),python==3.8.2 并且工作 [ref: https://developer.apple.com/metal/张量流插件/]:
在 x86 终端上创建一个 venv,即 Rosetta 终端(参见:https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g) 即环境设置: x86 : AMD 创建 venv:python3 -m venv ~/PATH/tensorflow-metal(用你的真实路径替换 PATH) 激活 venv: source ~/PATH/tensorflow-metal/bin/activate 更新pip:python -m pip install -U pip
安装您需要的任何库/包。例如: 例如:pip install matplotlib jupyterlab
安装基础张量流: python -m pip install tensorflow-macos
安装金属插件: python -m pip install tensorflow-metal
祝你好运和干杯!