
keras
农民小飞侠
如果放弃了,那还谈什么理想
展开
-
keras 用了ImageDataGenerator(1.0/255)之后的predict和predict_generator预测结果不一致的问题
用keras写图像分类的代码的时候,我们一般使用imagedatagenerator:ImageDataGenerator(1.0/255)示例代码:test_datagen = ImageDataGenerator(1.0/255)test_data_dir = './data_v1'IMAGE_SIZE=(128,128)batch_size = 32classes=[]with open("labels.txt","r") as f: for line in f.readl原创 2021-07-25 09:32:44 · 680 阅读 · 0 评论 -
keras “AttributeError: ‘str‘ object has no attribute ‘decode‘ “
今天在运行keras代码加载resnet34的预训练模型的时候,出现了下面的错误:“AttributeError: ‘str‘ object has no attribute ‘decode‘ 解决方法pip install h5py==2.10 -i https://pypi.doubanio.com/simple日志(pointnet) ➜ B13208 pip install h5py==2.10 -i https://pypi.doubanio.com/simpleLooking原创 2021-06-29 23:18:25 · 635 阅读 · 1 评论 -
ubuntu18.04 tensorflow 1.14运行程序的时候出现cuDNN failed to initialize
今天再运行程序的时候出现了下面的错误:2020-02-12 13:06:06.483007: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cp...原创 2020-02-12 13:08:23 · 2012 阅读 · 0 评论 -
keras flask (Could not find resource: localhost/res4b_branch2a/bias)
今天在用keras flask部署模型的时候,出现了下面的错误:File "app.py", line 132, in predict preds = model.predict(image) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/engine/training.py", line...原创 2019-12-27 23:24:51 · 1514 阅读 · 0 评论 -
keras ImportError: cannot import name 'get_source_inputs'
今天在运行efficientnet程序的时候,出现了下面的错误: from ._conv import register_converters as _register_convertersUsing TensorFlow backend.Traceback (most recent call last): File "run.py", line 10, in <module...原创 2019-11-21 21:19:02 · 3330 阅读 · 1 评论 -
keras module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
今天在运行kreas的时候,出现了下面的错误: File "/home/eric/anaconda3/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in <module> from .. import backend as K File "/home/eric/anaconda3/lib...原创 2019-11-14 21:05:59 · 2337 阅读 · 0 评论 -
keras plot一个模型
我们在跑模型的时候,都想输出一下模型的大致形状,keras提供了一个很好的接口,通过短短的几行代码就行了,首先需要安装必要的包:pip install pydotpip install graphviz在model,定义好以后,输入下面的代码可以输出了:from keras.utils import plot_modelplot_model(model,show_shape...原创 2019-09-08 11:28:24 · 177 阅读 · 0 评论 -
keras flow from directory显示label index
keras imageDataGenerator封装了很多,其中有一个flow from directory函数能够直接把文件夹里面的子文件夹当作label,然后做一个分类的训练。 rootDir='/home/eric/data/scene' # train_path='group0_train.txt' # valid_path='group0_valid.txt'...原创 2019-07-08 23:27:47 · 2533 阅读 · 0 评论 -
python keras bert训练Sanders Analytics Twitter Sentiment Corpus
Sanders Analytics Twitter Sentiment Corpus是一个推特情感分析的数据集,用bert 模型训练的效果还不错,好像达到了92.6%,这里把代码分享出来。数据集可从这个网址下载:http://www.keenformatics.com/articles/2015-07/sentiment-analysis-lexicons-and-datasets#sanders...原创 2019-05-06 20:25:12 · 866 阅读 · 4 评论 -
python keras bert ChnSentiCorp情感分析酒店评论分类
今天帮助了以为外国人做了一下keras版本的中文情感分析,我这里没有去掉标点符号,停用词这些,有兴趣的读者可以自己实现。我这里把代码分享出来。数据集下载地址为:http://file.hankcs.com/corpus/ChnSentiCorp.zip环境keras2.2.4 ubuntu 16.04 python 3.6 tensorflow-gpu2.2.4 pip...原创 2019-05-06 20:09:57 · 3277 阅读 · 0 评论 -
ValueError: If printing histograms, validation_data must be provided, and cannot be a generator.
今天在用tensorboard的时候遇见了下面的错误:Traceback (most recent call last): File "vgg16_finetune.py", line 368, in <module> callbacks=[tbCallBack,csvlog,checkpointer]) File "/home/eric/anaconda3/li...原创 2019-04-05 13:20:37 · 2701 阅读 · 2 评论 -
StopIteration: 'PngImageFile' object is not subscriptable
我的环境是ubuntu 16.04, keras 2.1.5,然后在运行vgg代码的时候,出现了如下的错误:Traceback (most recent call last): File "/home/eric/anaconda3/lib/python3.6/site-packages/keras/utils/data_utils.py", line 578, in get in...原创 2019-04-05 13:02:55 · 7917 阅读 · 5 评论 -
keras multiply TypeError: __init__() takes 1 positional argument but 2 were given
我的keras版本为Keras 2.1.5今天在用keras multiply的时候发现了上述的错误:Traceback (most recent call last): File "models.py", line 186, in <module> include_tweet=configs['include_tweet']) File "models....原创 2019-02-27 09:54:58 · 2522 阅读 · 0 评论 -
UserWarning: Update your `Model` call to the Keras 2 API: `Model(outputs=Tensor("lo..., inputs=[<tf.
我今天在调试代码的时候发现了这样一个警告,虽然对程序运行没什么大的影响,但是百度居然搜不到答案,这里我查了一点资料,我用的是keras 2我的警告信息为:HARRISON_data.py:114: UserWarning: Update your `Model` call to the Keras 2 API: `Model(outputs=Tensor("lo..., inputs=[<tf.Te原创 2018-01-22 15:59:33 · 4275 阅读 · 2 评论 -
TypeError Expected int32 got tensorflow python ops variables Variable object at 0x117ea3a10 of t
今天在运行别人的demo程序的时候,发现了一个错误,百思不得其解,明明没干啥,运行别人的demo也出错,我的错误信息为Traceback (most recent call last): File "model.py", line 23, in <module> model.add(LSTM(100)) File "//anaconda/lib/pyth...原创 2018-03-04 10:57:56 · 2935 阅读 · 0 评论 -
could not create cudnn handle: CUDNN_STATUS_NOT_INITIALIZED
今天我在运行keras版本的cnn rnn classifier的时候,报了如下的错误:totalMemory: 10.91GiB freeMemory: 10.20GiB2018-05-08 21:27:29.962822: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: ...原创 2018-05-08 21:39:21 · 7865 阅读 · 0 评论 -
keras的axis的解读
我们在写keras的代码的时候会遇见下面的类似场景:atten_mul=merge([image_embedding,attention_probs],mode='dot',dot_axes=(1,1))然后会经常困惑dot_axes那个括号里面的是啥意思,这里举个例子,如果一个张量的大小为:(19,19,5,80)axis = 0 - 19 elementsaxis = 1 - 19 eleme...原创 2018-05-12 22:50:28 · 3216 阅读 · 0 评论 -
TypeError: softmax() got an unexpected keyword argument 'axis'
今天我装了tensorflow-gpu 1.4, keras 2.1.6发现运行keras模型的时候出现了以下的错误:、Traceback (most recent call last): File "models.py", line 24, in <module> model = NIH() File "models.py", line 19, in NIH ...原创 2018-04-29 22:01:47 · 19710 阅读 · 11 评论 -
TypeError: _obtain_input_shape() got an unexpected keyword argument 'include_top
我在用keras跑深度学习预训练模型的时候发现了这个问题:ning-models$ python mobilenet.py /home/eric/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from...原创 2018-06-16 14:27:02 · 3113 阅读 · 0 评论 -
keras 自定义ImageDataGenerator用于多标签分类
感想keras提供了flow_from_directory用于单个标签分类,但是对图片的多标签分类没有支持,这就需要我们自己动手实现ImageDataGenerator,我这里把我实现的用于多标签分类的自定义DataGenerator分享出来,读者可以根据自己的情况来进行修改。数据集我用的是经过整理了之后的NUS-WIDE数据集,下载地址为:https://download.csdn.ne...原创 2018-11-28 22:25:13 · 6529 阅读 · 16 评论 -
python3 keras获取GRU的每一个时刻的输出,,切分GRU的输出示例
1. keras的GRU很好用,return_sequences,False 返回单个, true 返回全部time step 的 hidden state值。2. 但是keras的time step是根据输入决定的,这里我们在处理的时候,可能就需要分割以下某一层的数据,然后输入到后面的不同的层中,但是我们在对tensor操作的时候,会产生很多莫名其妙的错误,这里我写一个跟别人写的示例代码,分...原创 2018-12-22 12:10:14 · 2995 阅读 · 0 评论 -
Keras2.x GRUCell使用示例
看过keras的人会发现有一个GRUCell,LSTMCell这样的东西,其实就是一个RNN单元,然后可能会有人去用它,但是发现按照常规的方法用的话会报错,这里我提供了一个示例代码,这个东西其实可以和RNN来配合使用:直接上代码:from keras.models import Modelfrom keras.layers import *encoder_inputs=Inpu...原创 2019-01-12 10:32:02 · 1246 阅读 · 0 评论 -
keras 2.0:Encoder-Decoder Sequence-to-Sequence Model for Neural Machine Translation
感想最近可能会用到机器翻译的sequence to sequence模型,然后找了一个模型,把它跑通了,然后稍微改了一下。我把我改的方法记录下来,希望帮到大家的研究或者工程实践。试了一下csdn的markdown博客编写,感觉还不错环境python 3.5Keras (2.1.3)ubuntu 16.04tensorflow-gpu (1.4.1) 我的主要环境就是上原创 2018-01-21 20:30:42 · 2292 阅读 · 2 评论