无法在带有 BigSur 的 Mac M1 上使用 keras 模型

Ank*_*ita 8 python keras tensorflow tf.keras apple-m1

我正在尝试使用张量流的 keras 的顺序模型。当我执行以下语句时:

model.fit(x_train, y_train, epochs=20, verbose=True, validation_data=(x_dev, y_dev), batch_size=10)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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"
Run Code Online (Sandbox Code Playgroud)

我不明白如何解决它。谁能帮帮我吗。

从github上的这个问题,我了解到device.frequency()返回0可能是因为NominalCPUFrequency()返回1。但是,这个信息对我来说似乎太抽象了,我无法理解。

Zab*_*azi 5

前两个是不用担心的。

第三个是个问题。您安装的 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

Run Code Online (Sandbox Code Playgroud)

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

  • 我运行此程序并收到“错误:具有 ML 计算加速功能的 TensorFlow 仅在 macOS 11.0 及更高版本上可用。” 但我使用的是蒙特利 12.0.1 (3认同)