autokeras安装说明(Python)

安装autokeras时出现,报错:ModuleNotFoundError: No module named ‘kerastuner’ – Autokeras==1.0.3
这是个坑,你的cuda算力要大于3.5,正确安装方法为:
一、先用这行代码安装
2020年06月28号更新,试验过,后面加豆瓣源就快了!

pip install git+https://github.com/keras-team/keras-tuner.git@1.0.2rc0 -i https://pypi.douban.com/simple

二、安装autokeras

pip install autokeras==1.0.3 -i https://pypi.douban.com/simple

加了清华源,安装很快。

三、说scipy版本不匹配,再安装对应的版本

pip install scipy==1.4.1 -i https://pypi.douban.com/simple

2020年7月4号更新,此问题已经被修复,默认安装1.4.1版本了。

四、安装tensorflow-gpu=2.2.0

pip install tensorflow-gpu==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

因为conda安装时最大版本为2.1.0,所以采用pip安装,并用清华源。
也可以使用豆瓣源

pip install tensorflow-gpu==2.2.0 -i https://pypi.douban.com/simple

五、安装cuda

conda install cudatoolkit=10.1 cudnn=7.6.5

这样就好了,运行例子测试

from tensorflow.keras.datasets import mnist

import autokeras as ak
import os

# 指定第1号GPU训练
os.environ["CUDA_VISIBLE_DEVICES"] = "1"  #指定第1个gpu, 值从0开始

# Prepare the dataset.
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(x_train.shape)  # (60000, 28, 28)
print(y_train.shape)  # (60000,)
print(y_train[:3])  # array([7, 2, 1], dtype=uint8)

# Initialize the ImageClassifier.
clf = ak.ImageClassifier(max_trials=3)
# Search for the best model.
clf.fit(x_train, y_train, epochs=10)
# Evaluate on the testing data.
print('Accuracy: {accuracy}'.format(
    accuracy=clf.evaluate(x_test, y_test)))

结果为:

2020-06-27 10:58:33.462553: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
(60000, 28, 28)
(60000,)
[5 0 4]
2020-06-27 10:58:36.383872: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-06-27 10:58:36.408106: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1080 Ti computeCapability: 6.1
coreClock: 1.582GHz coreCount: 28 deviceMemorySize: 11.00GiB deviceMemoryBandwidth: 451.17GiB/s
2020-06-27 10:58:36.408509: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-06-27 10:58:36.413078: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-06-27 10:58:36.417132: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-06-27 10:58:36.418835: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-06-27 10:58:36.423328: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-06-27 10:58:36.426002: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-06-27 10:58:36.434870: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-06-27 10:58:36.435602: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-06-27 10:58:36.435996: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-06-27 10:58:36.443185: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2050d20ef80 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-06-27 10:58:36.443489: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-06-27 10:58:36.444072: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1080 Ti computeCapability: 6.1
coreClock: 1.582GHz coreCount: 28 deviceMemorySize: 11.00GiB deviceMemoryBandwidth: 451.17GiB/s
2020-06-27 10:58:36.444473: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-06-27 10:58:36.444679: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-06-27 10:58:36.444878: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-06-27 10:58:36.445075: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-06-27 10:58:36.445271: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-06-27 10:58:36.445472: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-06-27 10:58:36.445995: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-06-27 10:58:36.446630: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-06-27 10:58:37.011125: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-06-27 10:58:37.011341: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-06-27 10:58:37.011467: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-06-27 10:58:37.012205: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 8685 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
2020-06-27 10:58:37.014994: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2054cf68070 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-06-27 10:58:37.015271: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1080 Ti, Compute Capability 6.1
[Starting new trial]
Epoch 1/10
2020-06-27 10:58:39.905392: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-06-27 10:58:40.120250: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-06-27 10:58:49.373670: W tensorflow/stream_executor/gpu/redzone_allocator.cc:314] Internal: Invoking GPU asm compilation is supported on Cuda non-Windows platforms only
Relying on driver to perform ptx compilation. 
Modify $PATH to customize ptxas location.
This message will be only logged once.
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1756 - accuracy: 0.9475 - val_loss: 0.0648 - val_accuracy: 0.9820
Epoch 2/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0769 - accuracy: 0.9757 - val_loss: 0.0531 - val_accuracy: 0.9843
Epoch 3/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0619 - accuracy: 0.9806 - val_loss: 0.0535 - val_accuracy: 0.9850
Epoch 4/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0549 - accuracy: 0.9826 - val_loss: 0.0445 - val_accuracy: 0.9875
Epoch 5/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0464 - accuracy: 0.9852 - val_loss: 0.0485 - val_accuracy: 0.9876
Epoch 6/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0443 - accuracy: 0.9860 - val_loss: 0.0456 - val_accuracy: 0.9872
Epoch 7/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0373 - accuracy: 0.9875 - val_loss: 0.0430 - val_accuracy: 0.9882
Epoch 8/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0367 - accuracy: 0.9881 - val_loss: 0.0415 - val_accuracy: 0.9877
Epoch 9/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0355 - accuracy: 0.9882 - val_loss: 0.0392 - val_accuracy: 0.9896
Epoch 10/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.0303 - accuracy: 0.9902 - val_loss: 0.0410 - val_accuracy: 0.9893
[Trial complete]
[Trial summary]
 |-Trial ID: 833421c38ba01d6bf17b9d86317d04e7
 |-Score: 0.03915029019117355
 |-Best step: 8
 > Hyperparameters:
 |-classification_head_1/dropout_rate: 0.5
 |-classification_head_1/spatial_reduction_1/reduction_type: flatten
 |-image_block_1/augment: False
 |-image_block_1/block_type: vanilla
 |-image_block_1/conv_block_1/dropout_rate: 0.25
 |-image_block_1/conv_block_1/filters_0_0: 32
 |-image_block_1/conv_block_1/filters_0_1: 64
 |-image_block_1/conv_block_1/kernel_size: 3
 |-image_block_1/conv_block_1/max_pooling: True
 |-image_block_1/conv_block_1/num_blocks: 1
 |-image_block_1/conv_block_1/num_layers: 2
 |-image_block_1/conv_block_1/separable: False
 |-image_block_1/normalize: True
 |-optimizer: adam
[Starting new trial]
Epoch 1/10
1500/1500 [==============================] - 56s 37ms/step - loss: 2.1607 - accuracy: 0.2592 - val_loss: 2.0754 - val_accuracy: 0.3126
Epoch 2/10
1500/1500 [==============================] - 56s 38ms/step - loss: 1.9579 - accuracy: 0.3263 - val_loss: 3.0966 - val_accuracy: 0.2032
Epoch 3/10
1500/1500 [==============================] - 57s 38ms/step - loss: 1.8847 - accuracy: 0.3406 - val_loss: 7.0512 - val_accuracy: 0.2048
Epoch 4/10
1500/1500 [==============================] - 57s 38ms/step - loss: 1.7557 - accuracy: 0.3854 - val_loss: 1.3057 - val_accuracy: 0.5654
Epoch 5/10
1500/1500 [==============================] - 57s 38ms/step - loss: 1.5620 - accuracy: 0.4529 - val_loss: 1.3604 - val_accuracy: 0.5273
Epoch 6/10
1500/1500 [==============================] - 56s 37ms/step - loss: 1.8959 - accuracy: 0.3353 - val_loss: 1.5162 - val_accuracy: 0.4468
Epoch 7/10
1500/1500 [==============================] - 56s 38ms/step - loss: 1.4665 - accuracy: 0.4804 - val_loss: 1.4122 - val_accuracy: 0.5583
Epoch 8/10
1500/1500 [==============================] - 56s 37ms/step - loss: 1.3273 - accuracy: 0.5353 - val_loss: 1.0694 - val_accuracy: 0.6227
Epoch 9/10
1500/1500 [==============================] - 56s 37ms/step - loss: 1.2512 - accuracy: 0.5603 - val_loss: 7.5444 - val_accuracy: 0.6159
Epoch 10/10
1500/1500 [==============================] - 57s 38ms/step - loss: 1.3119 - accuracy: 0.5441 - val_loss: 1.1232 - val_accuracy: 0.6106
[Trial complete]
[Trial summary]
 |-Trial ID: 6f2e6be1e88f0a039f931bf22a28ce7d
 |-Score: 1.0693740844726562
 |-Best step: 7
 > Hyperparameters:
 |-classification_head_1/dropout_rate: 0
 |-image_block_1/augment: True
 |-image_block_1/block_type: resnet
 |-image_block_1/image_augmentation_1/horizontal_flip: True
 |-image_block_1/image_augmentation_1/vertical_flip: True
 |-image_block_1/normalize: True
 |-image_block_1/res_net_block_1/conv3_depth: 4
 |-image_block_1/res_net_block_1/conv4_depth: 6
 |-image_block_1/res_net_block_1/pooling: avg
 |-image_block_1/res_net_block_1/version: v2
 |-optimizer: adam
[Starting new trial]
Epoch 1/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.4535 - accuracy: 0.8895 - val_loss: 0.1098 - val_accuracy: 0.9680
Epoch 2/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1711 - accuracy: 0.9501 - val_loss: 0.0778 - val_accuracy: 0.9762
Epoch 3/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1494 - accuracy: 0.9560 - val_loss: 0.0721 - val_accuracy: 0.9796
Epoch 4/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1334 - accuracy: 0.9606 - val_loss: 0.0944 - val_accuracy: 0.9730
Epoch 5/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1341 - accuracy: 0.9616 - val_loss: 0.0667 - val_accuracy: 0.9808
Epoch 6/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1224 - accuracy: 0.9647 - val_loss: 0.0612 - val_accuracy: 0.9812
Epoch 7/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1138 - accuracy: 0.9667 - val_loss: 0.0740 - val_accuracy: 0.9799
Epoch 8/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1087 - accuracy: 0.9682 - val_loss: 0.0633 - val_accuracy: 0.9818
Epoch 9/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1101 - accuracy: 0.9675 - val_loss: 0.0536 - val_accuracy: 0.9838
Epoch 10/10
1500/1500 [==============================] - 6s 4ms/step - loss: 0.1075 - accuracy: 0.9691 - val_loss: 0.0574 - val_accuracy: 0.9841
[Trial complete]
[Trial summary]
 |-Trial ID: 15ba5def5f292232619aac183fac037e
 |-Score: 0.053594209253787994
 |-Best step: 8
 > Hyperparameters:
 |-classification_head_1/dropout_rate: 0.5
 |-classification_head_1/spatial_reduction_1/reduction_type: flatten
 |-image_block_1/augment: False
 |-image_block_1/block_type: vanilla
 |-image_block_1/conv_block_1/dropout_rate: 0.5
 |-image_block_1/conv_block_1/filters_0_0: 64
 |-image_block_1/conv_block_1/filters_0_1: 32
 |-image_block_1/conv_block_1/filters_1_0: 64
 |-image_block_1/conv_block_1/filters_1_1: 256
 |-image_block_1/conv_block_1/kernel_size: 5
 |-image_block_1/conv_block_1/max_pooling: False
 |-image_block_1/conv_block_1/num_blocks: 1
 |-image_block_1/conv_block_1/num_layers: 2
 |-image_block_1/conv_block_1/separable: False
 |-image_block_1/image_augmentation_1/horizontal_flip: True
 |-image_block_1/image_augmentation_1/vertical_flip: True
 |-image_block_1/normalize: False
 |-image_block_1/res_net_block_1/conv3_depth: 8
 |-image_block_1/res_net_block_1/conv4_depth: 23
 |-image_block_1/res_net_block_1/pooling: avg
 |-image_block_1/res_net_block_1/version: next
 |-optimizer: adam
1875/1875 [==============================] - 5s 3ms/step - loss: 0.1586 - accuracy: 0.9519
313/313 [==============================] - 1s 2ms/step - loss: 0.0531 - accuracy: 0.9810
Accuracy: [0.05307671055197716, 0.9810000061988831]
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.iter
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.beta_1
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.beta_2
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.decay
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.learning_rate
WARNING:tensorflow:A checkpoint was restored (e.g. tf.train.Checkpoint.restore or tf.keras.Model.load_weights) but not all checkpointed values were used. See above for specific issues. Use expect_partial() on the load status object, e.g. tf.train.Checkpoint.restore(...).expect_partial(), to silence these warnings, or use assert_consumed() to make the check explicit. See https://www.tensorflow.org/guide/checkpoint#loading_mechanics for details.
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.iter
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.beta_1
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.beta_2
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.decay
WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.learning_rate
WARNING:tensorflow:A checkpoint was restored (e.g. tf.train.Checkpoint.restore or tf.keras.Model.load_weights) but not all checkpointed values were used. See above for specific issues. Use expect_partial() on the load status object, e.g. tf.train.Checkpoint.restore(...).expect_partial(), to silence these warnings, or use assert_consumed() to make the check explicit. See https://www.tensorflow.org/guide/checkpoint#loading_mechanics for details.

Process finished with exit code 0

完成!

本站所有文章均为原创,欢迎转载,请注明文章出处:https://blog.csdn.net/weixin_45092662。百度和各类采集站皆不可信,搜索请谨慎鉴别。技术类文章一般都有时效性,本人习惯不定期对自己的博文进行修正和更新,因此请访问出处以查看本文的最新版本。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值