keras

Implementing Attention in Keras

梦想的初衷 提交于 2021-02-11 07:24:18
问题 I am trying to implement attention in keras over a simple lstm: model_2_input = Input(shape=(500,)) #model_2 = Conv1D(100, 10, activation='relu')(model_2_input) model_2 = Dense(64, activation='sigmoid')(model_2_input) model_2 = Dense(64, activation='sigmoid')(model_2) model_1_input = Input(shape=(None, 2048)) model_1 = LSTM(64, dropout_U = 0.2, dropout_W = 0.2, return_sequences=True)(model_1_input) model_1, state_h, state_c = LSTM(16, dropout_U = 0.2, dropout_W = 0.2, return_sequences=True,

Implementing Attention in Keras

我只是一个虾纸丫 提交于 2021-02-11 07:24:11
问题 I am trying to implement attention in keras over a simple lstm: model_2_input = Input(shape=(500,)) #model_2 = Conv1D(100, 10, activation='relu')(model_2_input) model_2 = Dense(64, activation='sigmoid')(model_2_input) model_2 = Dense(64, activation='sigmoid')(model_2) model_1_input = Input(shape=(None, 2048)) model_1 = LSTM(64, dropout_U = 0.2, dropout_W = 0.2, return_sequences=True)(model_1_input) model_1, state_h, state_c = LSTM(16, dropout_U = 0.2, dropout_W = 0.2, return_sequences=True,

Keras - How to remove useless dimension without hurting the computation graph?

旧巷老猫 提交于 2021-02-11 07:16:45
问题 While generating a deep learning model, I used K.squeeze function to squeeze useless dimension when the first two dimensions were None shape. import keras.backend as K >>> K.int_shape(user_input_for_TD) (None, None, 1, 32) >>> K.int_shape(K.squeeze(user_input_for_TD, axis=-2)) (None, None, 32) However, this gives below error, It seems like K.squeeze function hurts the computation graph, is there any solution to escape from this issue? Maybe that function does not support calculating gradients

How do I connect two keras models into one model?

て烟熏妆下的殇ゞ 提交于 2021-02-11 05:55:39
问题 Let's say I have a ResNet50 model and I wish to connect the output layer of this model to the input layer of a VGG model. This is the ResNet model and the output tensor of ResNet50: img_shape = (164, 164, 3) resnet50_model = ResNet50(include_top=False, input_shape=img_shape, weights = None) print(resnet50_model.output.shape) I get the output: TensorShape([Dimension(None), Dimension(6), Dimension(6), Dimension(2048)]) Now I want a new layer where I reshape this output tensor to (64,64,18) Then

How do I connect two keras models into one model?

穿精又带淫゛_ 提交于 2021-02-11 05:55:17
问题 Let's say I have a ResNet50 model and I wish to connect the output layer of this model to the input layer of a VGG model. This is the ResNet model and the output tensor of ResNet50: img_shape = (164, 164, 3) resnet50_model = ResNet50(include_top=False, input_shape=img_shape, weights = None) print(resnet50_model.output.shape) I get the output: TensorShape([Dimension(None), Dimension(6), Dimension(6), Dimension(2048)]) Now I want a new layer where I reshape this output tensor to (64,64,18) Then

【笔记】机器学习

萝らか妹 提交于 2021-02-11 05:29:34
学习笔记: 章节 简介 1 - Introduction & next step 机器学习介绍 & 机器学习下一步 2 - Regression + Demo 回归 & 示例代码 3 - Bias & Variance 偏差和方差 4 - Gradient Descent 梯度下降方法 5 - Classification 分类 6 - Logistic Regression 对数几率回归(逻辑回归) 7 - Deep Learning 深度学习介绍 8 - Backpropagation 反向传播 9 - Keras Demo Keras代码示例 10 - Tips for Training DNN 深度学习技巧 11 - Keras Demo2 & Fizz Buzz Keras代码优化 12 - CNN 卷积神经网络 13 - Why Deep 为什么要用深度学习 Explainable ML 可解释性机器学习 Transformer Transformer及注意力机制 ELMO、BERT、GPT ELMO、BERT、GPT-2、ERNIE 课后作业: Week 1: 矩阵运算,图片操作 Week 2: CEO利润预测 论文阅读: An overview of gradient descent optimization algorithms 参考资料: 李宏毅 2017

Tensorflow variable initialization inside loss function

左心房为你撑大大i 提交于 2021-02-11 04:52:39
问题 I have an object detection model implemented in tensorflow.keras (version 1.15). I am trying to implement a modified (hybrid) loss function in my model. Basically I need a few variables defined in my loss function because I am processing the y_true and y_pred provided in my classification loss function (a focal loss to be exact). So, I naturally resided in implementing my ops inside the loss function. I have defined a WrapperClass to initialize my variables: class LossWrapper(object): def _

Tensorflow variable initialization inside loss function

拥有回忆 提交于 2021-02-11 04:52:28
问题 I have an object detection model implemented in tensorflow.keras (version 1.15). I am trying to implement a modified (hybrid) loss function in my model. Basically I need a few variables defined in my loss function because I am processing the y_true and y_pred provided in my classification loss function (a focal loss to be exact). So, I naturally resided in implementing my ops inside the loss function. I have defined a WrapperClass to initialize my variables: class LossWrapper(object): def _

tensorflow 模型权重导出

亡梦爱人 提交于 2021-02-11 02:35:28
tensorflow在保存权重模型时多使用tf.train.Saver().save 函数进行权重保存,保存的ckpt文件无法直接打开,不利于将模型权重导入到其他框架使用(如Caffe、Keras等)。 好在tensorflow提供了相关函数 tf.train.NewCheckpointReader 可以对ckpt文件进行权重查看,因此可以通过该函数进行数据导出。 1 import tensorflow as tf 2 import h5py 3 4 cpktLogFileName = r ' ./checkpoint/checkpoint ' # cpkt 文件路径 5 with open(cpktLogFileName, ' r ' ) as f: 6 # 权重节点往往会保留多个epoch的数据,此处获取最后的权重数据 7 cpktFileName = f.readline().split( ' " ' )[1 ] 8 9 h5FileName = r ' ./model/net_classification.h5 ' 10 11 reader = tf.train.NewCheckpointReader(cpktFileName) 12 f = h5py.File(h5FileName, ' w ' ) 13 t_g = None 14 for key in sorted

plot Roc curve using keras

左心房为你撑大大i 提交于 2021-02-10 20:51:57
问题 I have a neural network model and I am using KerasClassifier and then using KFold for cross-validation. Now I am having issues in plotting the ROC curve. I have tried few codes but most of them is giving me an error of multi-labeled is not interpreted. I have the following code till my neural network produces the accuracy. I will be thankful if anyone can help me with the later part of the code. import numpy as np import pandas as pd from keras.layers import Dense, Input from keras.models