
keras
文章平均质量分 80
xiewenbo
互联网广告行业呆过几年,旅游公司呆过几年,对机器学习,自然语言处理,图像识别,个性化推荐 有兴趣
展开
-
keras bilstm 序列标注
from random import randomfrom numpy import arrayfrom numpy import cumsumfrom keras.models import Sequentialfrom keras.layers import LSTMfrom keras.layers import Densefrom keras.layers import TimeDistributed # create a sequence classification insta.转载 2020-06-07 13:00:06 · 408 阅读 · 0 评论 -
keras: 在构建LSTM模型时,使用变长序列的方法
众所周知,LSTM的一大优势就是其能够处理变长序列。而在使用keras搭建模型时,如果直接使用LSTM层作为网络输入的第一层,需要指定输入的大小。如果需要使用变长序列,那么,只需要在LSTM层前加一个Masking层,或者embedding层即可。 1 2 3 4 5 fromkeras.layersimportMasking, Embedding fromkeras.layersimportLSTM mod...转载 2020-06-07 12:33:38 · 714 阅读 · 0 评论 -
Keras 常用callback function
TensorBoard通过结合TF的TensorBoard将网络结构以及运行时状态可视化from keras.callbacks import TensorBoardmodel.fit([encoder_input_data, decoder_input_data], decoder_target_data, batch_size=batch_size, epo...原创 2018-03-21 15:32:38 · 2129 阅读 · 0 评论 -
model fine tune & get output by layer
从VGG19的任意中间层中抽取特征from keras.applications.vgg19 import VGG19from keras.preprocessing import imagefrom keras.applications.vgg19 import preprocess_inputfrom keras.models import Modelimport numpy as npbas...转载 2018-03-21 17:51:27 · 566 阅读 · 0 评论 -
keras 关于 dropout 的一点讨论
dropout in training and testing #5357 wenouyang commented on 11 Feb 2017In this link, devinplatt gives the following way to include dropout in training,model = Sequential()model.add(Dropout(0.5, inpu...转载 2018-03-26 15:08:22 · 6640 阅读 · 0 评论 -
keras fit_generator
Let us suppose that your data are images. If you have many images you probably won't be able to load all of them in memory and you would like to read from disk in batches.Keras flow_from _directory ...转载 2018-10-16 19:42:55 · 598 阅读 · 0 评论 -
multi-thread for keras model / what is model._make_predict_function() used for?
when call the predict for multi-thread, there is always exception: tensor *** is not an element of this graph.two ways to solve this problem:1) call model._make_predict_function() after load model...原创 2018-11-07 12:02:23 · 3277 阅读 · 3 评论 -
What's the difference between shared embedding and embedding with multi-hot input in Keras
Suppose the input is a index of 3 items such as (1,2,3), I want to get 3 embedding vector corresponding to the 3 items and then get the average of 3 vectors. Here are two method:method 1:item1_in...转载 2019-03-21 11:03:33 · 863 阅读 · 0 评论 -
处理类别不平衡的数据的分类问题
处理不平衡的数据集的时候,可以使用对数据加权来提高数量较小类的被选中的概率,具体方式如下fit(self, x, y, batch_size=32, nb_epoch=10, verbose=1, callbacks=[], validation_split=0.0, validation_data=None, shuffle=True, class_weight=None, sampl...转载 2019-03-29 10:32:51 · 693 阅读 · 0 评论 -
keras 自定义Layer
编写你自己的 Keras 层对于简单、无状态的自定义操作,你也许可以通过 layers.core.Lambda 层来实现。但是对于那些包含了可训练权重的自定义层,你应该自己实现这种层。这是一个 Keras2.0 中,Keras 层的骨架(如果你用的是旧的版本,请更新到新版)。你只需要实现三个方法即可:build(input_shape): 这是你定义权重的地方。这个方法必须设 self....转载 2019-04-12 15:27:09 · 4777 阅读 · 0 评论 -
How to define a keras custom loss function in simple mathematical operation
https://blog.youkuaiyun.com/xiewenbo/article/details/89255424I define a custom functionmy_sigmoidas following:import mathdef my_sigmoid(x): a = 1/ ( 1+math.exp( -(x-300)/30 ) ) return aA...转载 2019-04-12 19:55:44 · 468 阅读 · 0 评论 -
keras 指定GPU
计数下标从1开始例:CUDA_VISIBLE_DEVICES=2 python3 predict_3.pyHow can I run a Keras model on multiple GPUs?We recommend doing so using the TensorFlow backend. There are two ways to run a single model on multip...原创 2018-03-04 23:08:43 · 1574 阅读 · 0 评论 -
keras 对于大数据的训练,无法一次性载入内存,使用迭代器
转处:http://blog.youkuaiyun.com/lujiandong1/article/details/54869170说明:我是在keras的官方demo上进行修改https://github.com/fchollet/keras/blob/master/examples/imdb_cnn.py1、几点说明,从文件中读入数据,会降低GPU的使用率,如果能够直接将数据载入内存,GPU的使用率会比较...转载 2018-03-04 00:08:59 · 6291 阅读 · 1 评论 -
Text Generation With LSTM Recurrent Neural Networks in Python with Keras
Recurrent neural networks can also be used as generative models.This means that in addition to being used for predictive models (making predictions) they can learn the sequences of a problem and then ...转载 2017-04-26 23:45:11 · 1199 阅读 · 0 评论 -
keras Usage of metrics 评价指标
Usage of metricsA metric is a function that is used to judge the performance of your model. Metric functions are to be supplied in the metrics parameter when a model is compiled.model.compile(转载 2017-07-05 19:50:32 · 10294 阅读 · 0 评论 -
docker keras 下 ImportError: cannot import name ctc_ops
Using TensorFlow backend.Traceback (most recent call last): File "", line 1, in File "/root/miniconda2/lib/python2.7/site-packages/keras/__init__.py", line 3, in from . import activatio原创 2017-07-05 19:43:26 · 3882 阅读 · 0 评论 -
lstm 做 文本的情感分析
github上可以参考的代码https://github.com/BUPTLdy/Sentiment-Analysis/blob/master/code/Sentiment_lstm.pyhttps://github.com/life-is-good/CommentFilter转载 2017-07-05 19:50:47 · 4439 阅读 · 0 评论 -
keras Embedding layer [Arguments input_dim: int > 0. Size of the vocabulary, i.e. maximum integer ]
keras.layers.embeddings.Embedding(input_dim, output_dim, embeddings_initializer='uniform',embeddings_regularizer=None, activity_regularizer=None, embeddings_constraint=None,mask_zero=Fal转载 2017-07-06 11:46:32 · 719 阅读 · 0 评论 -
[code review] lstm - sentiment analysis
Long short-term memory (LSTM) is a recurrent neural network (RNN) architecture (an artificial neural network) published in 1997 by Sepp Hochreiter and Jürgen Schmidhuber. Like most RNNs, an LSTM netwo原创 2017-07-06 17:12:30 · 1007 阅读 · 0 评论 -
Saving a Python dict to a file using pickle
Per Programming Python, 3rd Edition, there are a number of methods to store persistent data with Python:I often use flat files to read or write text (string) data using the os library.Flat files转载 2017-07-06 17:16:29 · 586 阅读 · 0 评论 -
Save and Load Your Keras Deep Learning Models
出自:https://machinelearningmastery.com/save-load-keras-deep-learning-models/Keras is a simple and powerful Python library for deep learning.Given that deep learning models can take hours,转载 2017-08-30 19:49:16 · 607 阅读 · 0 评论 -
使用CNN进行文本分类
1.卷积神经网络简介卷积神经网络(Convolutional Neural Network,CNN)是一种前馈神经网络,它的人工神经元可以响应一部分覆盖范围内的周围单元,对于大型图像处理有出色表现。它包括卷积层(alternating convolutional layer)和池层(pooling layer)。卷积神经网络是近年发展起来,并引起广泛重视的一种高效识别方法。20原创 2017-09-06 23:08:33 · 8410 阅读 · 14 评论 -
Keras同时用多张显卡训练网络
References.官方文档:multi_gpu_model以及Googlehttps://www.jianshu.com/p/db0ba022936f0. 误区目前Keras是支持了多个GPU同时训练网络,非常容易,但是靠以下这个代码是不行的。os.environ["CUDA_VISIBLE_DEVICES"] = "1,2"当你监视GPU的使用情况(nvidia-smi -l 1)的时候会...转载 2018-03-16 10:35:11 · 1544 阅读 · 0 评论 -
Usage of loss functions
转自:https://keras.io/losses/A loss function (or objective function, or optimization score function) is one of the two parameters required to compile a model:model.compile(loss='mean_squared_err转载 2017-04-20 22:27:50 · 639 阅读 · 0 评论