自动深度学习auto-pytorch安装
创始人
2024-04-30 00:43:58
0

安装

实测window安装不了,自己捣鼓了半天终于要成功时,报了个错

ImportError: No module named resource

pip安装也没解决,最后百度说是resource模块在windows上是不可用的
所以只能放弃

Mac 安装auto-pytorch

pip install swig
pip install pyrfr
pip install autoPyTorch

正常情况下就能安装好了

过程常见报错

1、lightgbm依赖

第一次使用报错:

OSError: dlopen(/Users/*/opt/anaconda3/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: /Users/
/opt/anaconda3/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so
Reason: tried: ‘/usr/local/opt/libomp/lib/libomp.dylib’ (no such file), ‘/usr/local/lib/libomp.dylib’ (no such file), ‘/usr/lib/libomp.dylib’ (no such file)

使用autoPyTorch需要安装lightgbm
解决方案:

pip uninstall lightgbm
conda install lightgbm

2、brew安装

bash: brew: command not found…

解决方案:
终端直接输入:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

过程中,国内景象选择清华大学,差不多十几分钟就好了

3、brew install报错

fatal: not in a git directory Error: Command failed with exit 128: git

先输入:brew -v
会提示相应的方法:

(base) MacBook-Pro:~ ***$ brew -v
Homebrew 3.6.16-8-g895d322
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)

将上面提示的两段代码输入终端运行即可:

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core 
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask 

实战

我们先使用官网案例验证下:

import os
import tempfile as tmp
import warningsfrom autoPyTorch.datasets.resampling_strategy import CrossValTypesos.environ['JOBLIB_TEMP_FOLDER'] = tmp.gettempdir()
os.environ['OMP_NUM_THREADS'] = '1'
os.environ['OPENBLAS_NUM_THREADS'] = '1'
os.environ['MKL_NUM_THREADS'] = '1'warnings.simplefilter(action='ignore', category=UserWarning)
warnings.simplefilter(action='ignore', category=FutureWarning)import sklearn.datasets
import sklearn.model_selection

from autoPyTorch.api.tabular_classification import TabularClassificationTaskX, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(X,y,random_state=1,
)api = TabularClassificationTask(# To maintain logs of the run, you can uncomment the# Following lines# temporary_directory='./tmp/autoPyTorch_example_tmp_01',# output_directory='./tmp/autoPyTorch_example_out_01',# delete_tmp_folder_after_terminate=False,# delete_output_folder_after_terminate=False,seed=42,
)api.search(X_train=X_train,y_train=y_train,X_test=X_test.copy(),y_test=y_test.copy(),dataset_name='Australian',optimize_metric='accuracy',total_walltime_limit=300,func_eval_time_limit_secs=50,#n_jobs= -1,memory_limit=None
)

api.search时,如果只加入了官网代码会报错

ValueError: current limit exceeds maximum limit

所以需要加上:

memory_limit=None

y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)# Print statistics from search
print(api.sprint_statistics())

{‘accuracy’: 0.8728323699421965}
autoPyTorch results:
Dataset name: Australian
Optimisation Metric: accuracy
Best validation score: 0.8713450292397661
Number of target algorithm runs: 52
Number of successful target algorithm runs: 6
Number of crashed target algorithm runs: 45
Number of target algorithms that exceeded the time limit: 1
Number of target algorithms that exceeded the memory limit: 0

这样就运行完成了
下一节,讲一下具体的用法

相关内容

热门资讯

利用Golang可选参数实现可... 本文讨论Golang函数可选参数及函数类型,以及如何利用可选函数类型实现可选模式。同时...
【学习笔记】[AGC040F]... 我是丝薄因为我不会GF 考虑纯组合意义的推导。因为我真的不会数学啊 设(x,d)(x,d)(x,d)...
java线程中断 interr... 1.  线程的状态: new -> 创建完线程,但是还没有启动runna...
16 | 如何做好面试后的复盘... 前言 前言:将经验转换为能力,就需要从经历的事情上总结复盘。 文章目...
Python基础学习七 类 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Py...
day 19 暴力枚举 注意:用long long 存答案P2241 统计方形(数据加强版&#x...
嵌入式理论复习题库(期末考试版... 一、填空题15*1=15 1. 要下载并调试 STM32 程序,可采用   ...
OSG三维渲染引擎编程学习之二... 目录 第三章:OSG场景组织 3.6 Transform变换节点 第三章:OSG场景组织 ...
cmake 04 使用 pyt... 本文目标 使用 python 写一个管理 cmake 工程的 cli 程序 参考 Python CL...
Java多线程(二)—— Re... ReentrantLock源码解析 ReentrantLock 是可重入的互斥锁,虽然...