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

3okqufwl  于 2023-01-30  发布在  Mac
关注(0)|答案(3)|浏览(234)

我正在尝试使用tensorflow Keras的顺序模型。当我执行以下语句时:
model.fit(x_train,y_train,时间点=20,详细信息=真,验证数据=(x_dev,y_dev),批处理大小=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,但是这个信息对我来说太抽象了,我无法理解。

zmeyuzjn

zmeyuzjn1#

前两个没什么好担心的。
第三个是个问题,你安装了不正确的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

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

iyfamqjs

iyfamqjs2#

我已经在macOS 11.4上完成了以下操作(尽管参考文档中说"操作系统要求macOS 12.0 +"),python == 3.8.2和工作[参考文档:https://developer.apple.com/metal/tensorflow-plugin/]:
1.在x86终端上创建venv,即Rosetta终端(参见:https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g),即环境设置:x86:AMD创建版本:python3 -m venv ~/PATH/tensorflow-metal(用你的真实路径替换PATH)激活venv:source ~/PATH/tensorflow-metal/bin/activate更新点:python -m pip install -U pip
1.安装您需要的任何库/包。例如:例如:pip install matplotlib jupyterlab
1.安装基础tensorflow 量:python -m pip install tensorflow-macos
1.安装金属插件:python -m pip install tensorflow-metal
祝你好运!

gudnpqoy

gudnpqoy3#

这可能一点帮助都没有,但由于我遇到了同样的问题,我设法让模型在没有这里提供的解决方案的情况下训练(我很快就会尝试),只是在进行train_test_split时像这样修改我的Y_test(0和1):(to_categorical(label)。因此:

X_train, X_test, Y_train, Y_test = train_test_split(dataset, 
                                                to_categorical(label), 
                                                test_size=.2, 
                                                random_state=42)

然后,在训练模型时,我得到了以下消息-我不完全理解:
2022年4月3日23时10分08秒94秒1296秒I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:112]已启用设备类型GPU的插件优化器。
因此,这并不是一个真正的解决方案,而更多的是一个临时的变通方案-或者它可能会给予人了解哪里出错了。

相关问题