![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Deep learning
Regnaiq
只是一个学生, 学无止境. 慢慢来, 比较快.
展开
-
matlab不构建网络来使用深度学习层操作数组
python里有tensor, 可以调用deep learning的API来处理. 类似的, matlab里有dlarray, 也就是深度学习的array. 同样也可以调用matlab深度学习的函数来处理.有时候需要深度学习的功能来处理数据, 比如利用pooling来处理一下数组. 但是matlab的普通数组没有支持的函数, 自己写又太麻烦.同样地, 类似的操作可以应用于卷积等. 感兴趣的用户可以参考更多。原创 2022-12-27 17:28:15 · 642 阅读 · 0 评论 -
Maltab用confusionchart画图classlabels的一个问题
confusionchart画图的时候可以设置不同class的名字, 比如下图注意, 这里Class的名字setosa, versicolor等是按字母顺序排列的, 而且大小写敏感. 无法自定义.原创 2022-07-03 16:02:11 · 920 阅读 · 1 评论 -
Keras: InternalError: Blas xGEMM launch failed
原因是GPU内存不够了.解决方法有以下几种:修改cuda或者cuDnn的版本. 但是好麻烦. 详细版本见这里.Reference[1] Blas xGEMMBatched launch failed的出现原因原创 2022-06-30 14:44:20 · 1013 阅读 · 0 评论 -
Keras如何应对无法一次性读入内存的大文件?
对于很小的数据集来说, 我们可以直接读进内存来训练模型:model.fit(x_train, y_train)那么如果数据量太大, 比如几十G, 该怎么办呢?什么是generator好在Keras的fit函数支持了generator. 我们可以分batch读取文件来进行训练, 达到节省内存的目的.网上很多介绍generator的文章都差不多过时了, 推荐python wiki.简单来说, 就是可以定义一个函数, 每次调用返回不会停止程序, 而是返回中间结果, 下次调用的时候会继续运行循环. 比原创 2021-08-02 11:23:22 · 578 阅读 · 0 评论 -
Keras之获取中间layer的output
大致有两种方法建一个新模型, output为那个layer使用K.function抽象出这个输出.先挖个坑. 详细见:Keras, How to get the output of each layer?原创 2021-07-23 20:14:30 · 501 阅读 · 0 评论 -
Keras之查看模型layer的层数
当模型很大的时候有时候需要查看模型某个layer对应的层数. 用model.summary()不大好使.可以用如下代码列举模型的层数:{i: v for i, v in enumerate(model.layers)}{0: <keras.layers.convolutional.Conv2D at 0x7f182bcd1710>, 1: <keras.layers.normalization.BatchNormalization at 0x7f1840981828>,原创 2021-07-23 20:04:07 · 1322 阅读 · 0 评论 -
Keras之删除训练好model的layer
Sequential API建一个新model, 然后把旧model的layer一层一层加进去model = Sequential()for layer in source_model.layers[:-1]: # 最后一层 model.add(layer)model.add(Dense(3, activation='softmax'))model.summary()Functional API把原来model某一层的output直接接到新的model上.predictions原创 2021-07-23 17:01:38 · 1192 阅读 · 4 评论 -
Keras保存复杂的model
Keras保存model的时候, 因为自定义的loss, metrics, lambda layer等总是会保存失败.写一个简单实用的方法: 保存model, 然后再需要用的时候先run代码, 建好model, 然后再导入weight. 省去不必要的麻烦.保存modelmodel.save('model.h5')把weight导入新modelnew_model.load_weights('model.h5')...原创 2021-07-23 16:52:22 · 122 阅读 · 0 评论 -
Keras loss/metrics类中的reduction type
以tf.keras.losses.MeanSquaredError为例:默认, 把所有值平均, 只返回一个值.SUM,把所有值加一起, 只返回一个值.NONE, 按最后一维的个数返回.原创 2021-07-22 16:59:57 · 180 阅读 · 0 评论 -
Keras: Cannot convert ‘auto‘ to EagerTensor of dtype float
看一下你自定义的loss function. 要先定义一个类, 再传入参数:loss=tf.keras.losses.MeanSquaredError(y_true,y_pred) #wrongm=tf.keras.losses.MeanSquaredError()loss=m(y_true,y_pred) #right原创 2021-07-22 16:54:37 · 860 阅读 · 0 评论 -
Cannot convert a symbolic Keras input/output to a numpy array TypeError
如果你自定义了loss, 出现了上述问题, 有三个解决办法:开头加上from tensorflow.python.framework.ops import disable_eager_executiondisable_eager_execution()编译时model.compile(...,experimental_run_tf_function=False) 在构建model之前del modelmodel = tf.keras.models.Model(inp, out原创 2021-07-22 16:51:55 · 2307 阅读 · 2 评论 -
tf.keras.backend与keras.backend的区别
我们可以看到网上很多keras代码还是用K.xxxx来作为后端函数来写的, 而且很多都可以直接用tf调用.这是因为:K是以前tensorflow还没有成为keras的默认后端时定义的函数, 对于其他后端比如theano和MXNet都适用。现在很多函数tf与k都一致了。 有一小部分比tf实现的更好, 比如tf.keras.backend.batch_normalization 。 也有的是K独有的, 比如tf.keras.backend.set_learning_phase参考: Redundan原创 2021-07-22 16:37:14 · 844 阅读 · 0 评论 -
will not use cuDNN kernels since it doesn‘t meet the criteria
CUDNN运行是有一定的要求的:’Keras API里有这样的说法:Based on available runtime hardware and constraints, this layer will choose different implementations (cuDNN-based or pure-TensorFlow) to maximize the performance. If a GPU is available and all the arguments to the laye原创 2021-07-22 14:12:55 · 1022 阅读 · 0 评论 -
Keras之layer: RepeatVector和TimeDistributed
Layer: RepeatVectorRepeatVector(10): 把向量复制10次. 比如原先的向量是(32, ) 之后就变成了(32,10)主要用于LSTM encoder. encoder得到的结果是一个一维feature向量, 但是decoder回去也是LSTM, 所以必须先重复10次当作是有时间步的, 才能输入decoder的LSTM中去.Layer: TimeDistributedTimeDistributed( Dense( 12 , input_shape=( 10 , 6原创 2021-07-19 11:13:50 · 1550 阅读 · 0 评论 -
Keras之GaussianDropout vs. Dropout vs. GaussianNoise Layers
Dropout随机令某些node的权重置零.GaussianNoise为结果添加均值为0的加性噪声.GaussianDropout为结果添加均值为1的乘性噪声.注意, GaussianDropout虽然名字有dropout, 但是并没有起到dropout的功能.原创 2021-07-08 17:40:43 · 749 阅读 · 0 评论 -
Keras之 failed with error CUPTI could not be loaded or symbol could not be found
添加环境变量:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\version\extras\CUPTI\libx64以管理员身份重新打开脚本/IDE详细可以见Tensorflow CUDA - CUPTI error: CUPTI could not be loaded or symbol could not be found原创 2021-07-08 17:30:32 · 1746 阅读 · 0 评论 -
python画混淆矩阵 confusion matrix
sklearn.metrics.plot_confusion_matrix可以直接画混淆矩阵, 但是好像要传入sklearn的classifier.贴一个自己写的函数, 自己定义起来比较方便:def plot_confusion_matrix(cm, classes, normalize=False, title='Confusion matrix', cmap原创 2021-06-18 15:53:00 · 827 阅读 · 0 评论 -
Keras之target data的label编码格式探讨
Keras支持one-hot coding的编码方式, 也是output默认的方式.以单标签多分类问题为例,如果target data的编码是one-hot, 那么就按照常规教程里所说,loss用categorical_crossentropy, accuracy用accuracy或者categorical_accuracy.如果traget data的编码是integer vector, 如[1,2,4,3,5,0],那么loss用sparse_categorical_crossentropy,原创 2021-06-18 14:48:17 · 337 阅读 · 0 评论 -
NotImplementedError: Cannot convert a symbolic Tensor (LSTM/strided_slice:0) to a numpy array
numpy版本的问题.把numpy降到1.19.2即可.详情看这里.原创 2021-06-15 22:56:06 · 8171 阅读 · 17 评论 -
Keras之打印模型出错: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.
安装pydot conda install pydot如果还出现上述错误, 重启spyder或者电脑即可.原创 2021-06-15 16:38:01 · 150 阅读 · 0 评论 -
Keras导入自定义metric模型报错: unknown metric function: Please ensure this object is passed to`custom_object‘
Keras的模型自定义了metric或者loss,在保存成后h5的时候没有问题, 但是在使用load_model导入的时候却会报错:unknown metric function: HammingScore. Please ensure this object is passed to the custom_objects argument.这是因为自定义的参数没有传递进去. 有两个解决办法:如果只需要做预测, 不再训练, 则可以直接加compile = False:model = ker原创 2021-06-12 20:41:02 · 9440 阅读 · 14 评论 -
Keras打印模型训练总用时
定义callback:from timeit import default_timer as timerclass TimingCallback(keras.callbacks.Callback): def __init__(self, logs={}): self.logs=[] def on_epoch_begin(self, epoch, logs={}): self.starttime = timer() def on_epoch_end原创 2021-06-11 20:54:59 · 725 阅读 · 2 评论 -
Keras自定义multilabel多标签分类的衡量标准
对于多标签分类而言, 自带的标准比如accuracy已经不在适用.hamming score是一个很好的标准, 详细可以参考这篇文章.贴一下自己写的自定义hamming score:import tensorflow as tfimport tensorflow.keras.backend as Kdef HammingScore(y_true, y_pred): y_true = tf.cast(y_true, tf.bool) y_pred = tf.greater(y_p原创 2021-06-10 20:04:28 · 463 阅读 · 0 评论 -
Keras学习踩坑记录
卸载windows的python:【python】python彻底卸载的方法【windows安装版卸载的示例】配置anaconda的环境变量:Anaconda的安装及其环境变量的配置详解PackagesNotFoundError: The following packages are not available from current channels的解决办法:在anaconda.org上搜想安装的包.查看需要的版本在哪个channel(比如在conda-forge)添加channe c原创 2021-06-02 22:10:13 · 339 阅读 · 0 评论 -
RTX 2080 Ti安装tensorflow, 配置GPU [2021-06-02]
网上太多的文章, 已经很老了, 完全不适用. 摸索了一天, 写一下如何安装tensorflow.安装anaconda. 包含python, 就不多说了.安装tensorflow. 现在GPU版和CPU版已经集成在一起了.pip install tensorflow在最新的tensorflow页面查看GPU的软件配置. 要严格按照上面说的下载和安装.下载Visual studio 2019 community 版, 否则显卡驱动无法正常安装.下载对应的Nvidia驱动, 安装. 不多说了原创 2021-06-02 22:50:47 · 1020 阅读 · 0 评论