windows anaconda python 3.7 安装 autokeras

windows anaconda python 3.7 安装 autokeras

注意1:autokeras 需要先安装pytorch,pytorch的安装参考这篇文章:windows anaconda python 3.7 安装 pytorch-gpu

注意2:autokeras 会帮你安装tensorflow的CPU版,如果你想使用tensorflow的GPU版,请参考这篇文章:windows anaconda python 3.7 安装keras-gpu tensorflow-gpu


autokeras 支持pip 安装:

pip install autokeras 

但是pip的包不是最新的,很可能在安装过程中报错,推荐使用GitHub进行安装:

git clone https://github.com/keras-team/autokeras.git
cd autokeras
pip install .

测试代码:

from keras.datasets import mnist
from autokeras import ImageClassifier
from autokeras.constant import Constant

if __name__ == '__main__':
    (x_train, y_train), (x_test, y_test) = mnist.load_data()
    x_train = x_train.reshape(x_train.shape + (1,))
    x_test = x_test.reshape(x_test.shape + (1,))
    clf = ImageClassifier(verbose=True, augment=False)
    clf.fit(x_train, y_train, time_limit=30 * 60)
    clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
    y = clf.evaluate(x_test, y_test)
    print(y * 100)

注意:推荐使用命令行跑,使用spyder跑程序会报错
运行结果如下:

Using TensorFlow backend.
Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex.
Saving Directory: C:\Users\peter\AppData\Local\Temp\autokeras_PIWS45
Preprocessing the images.
Preprocessing finished.

Initializing search.
Initialization finished.


+----------------------------------------------+
|               Training model 0               |
+----------------------------------------------+
Using TensorFlow backend.
Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex.
Epoch-1, Current Metric - 0:   0%|                                      | 0/465 [00:00<?, ? batch/s]C:\Users\peter\Anaconda3\lib\site-packages\torchvision\transforms\functional.py:206: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  mean = torch.tensor(mean, dtype=torch.float32)
C:\Users\peter\Anaconda3\lib\site-packages\torchvision\transforms\functional.py:207: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  std = torch.tensor(std, dtype=torch.float32)
                                                                                                    2<00:00, 35.63 batch/s]]]/s]
No loss decrease after 5 epochs.


Saving model.
+--------------------------------------------------------------------------+
|        Model ID        |          Loss          |      Metric Value      |
+--------------------------------------------------------------------------+
|           0            |   0.1937298059463501   |         0.9812         |
+--------------------------------------------------------------------------+


+----------------------------------------------+
|               Training model 1               |
+----------------------------------------------+
Using TensorFlow backend.
Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex.
Epoch-1, Current Metric - 0:   0%|                                      | 0/465 [00:00<?, ? batch/s]C:\Users\peter\Anaconda3\lib\site-packages\torchvision\transforms\functional.py:206: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  mean = torch.tensor(mean, dtype=torch.float32)
C:\Users\peter\Anaconda3\lib\site-packages\torchvision\transforms\functional.py:207: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  std = torch.tensor(std, dtype=torch.float32)
Epoch-6, Current Metric - 0.986:  13%|███▏                     | 60/465 [00:26<02:58,  2.27 batch/s]WARNING:root:TimeoutError occurred at train() :
Time is out.
Epoch-1, Current Metric - 0:   0%|                                      | 0/469 [00:00<?, ? batch/s]C:\Users\peter\Anaconda3\lib\site-packages\torchvision\transforms\functional.py:206: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  mean = torch.tensor(mean, dtype=torch.float32)
C:\Users\peter\Anaconda3\lib\site-packages\torchvision\transforms\functional.py:207: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  std = torch.tensor(std, dtype=torch.float32)
                                                                                                    <00:00, 55.67 batch/s]]]/s]]
No loss decrease after 30 epochs.

98.63

98.63还是不错的

猜你喜欢

转载自blog.csdn.net/zhangpeterx/article/details/89163410