开发手册 欢迎您!
软件开发者资料库

Python TensorFlow使用keras模型 Mac M1上报错(Check failed: 0 < gflops (0 vs. 0)type: "CPU")解决方法

执行代码: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_opt

执行代码:

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"

解决方法:

安装的TensorFlow版本不正确。需要使用支持Mac M1芯片的版本。运行以下bash脚本下载并安装TensorFlow。

脚本如下:

#!/bin/bashset -eVERSION=0.1alpha3INSTALLER_PACKAGE=tensorflow_macos-$VERSION.tar.gzINSTALLER_PATH=https://github.com/apple/tensorflow_macos/releases/download/v$VERSION/$INSTALLER_PACKAGEINSTALLER_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 1fi# This echo "Installation script for pre-release tensorflow_macos $VERSION.  Please visit https://github.com/apple/tensorflow_macos "echo "for instructions and license information."   echoecho "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]$ ]]thenexit 1fiechoecho "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   echo  exit 1}bash ./$INSTALLER_SCRIPT --prompt || graceful_error popdrm -rf $tmp_dir

参考文档https://github.com/apple/tensorflow_macos