keras-layer

What is the difference between an Embedding Layer and a Dense Layer?

自闭症网瘾萝莉.ら 提交于 2019-12-17 18:48:57
问题 The docs for an Embedding Layer in Keras say: Turns positive integers (indexes) into dense vectors of fixed size. eg. [[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]] I believe this could also be achieved by encoding the inputs as one-hot vectors of length vocabulary_size , and feeding them into a Dense Layer. Is an Embedding Layer merely a convenience for this two-step process, or is something fancier going on under the hood? 回答1: Mathematically, the difference is this: An embedding layer performs

TimeDistributed(Dense) vs Dense in Keras - Same number of parameters

北慕城南 提交于 2019-12-17 10:42:27
问题 I'm building a model that converts a string to another string using recurrent layers (GRUs). I have tried both a Dense and a TimeDistributed(Dense) layer as the last-but-one layer, but I don't understand the difference between the two when using return_sequences=True, especially as they seem to have the same number of parameters. My simplified model is the following: InputSize = 15 MaxLen = 64 HiddenSize = 16 inputs = keras.layers.Input(shape=(MaxLen, InputSize)) x = keras.layers.recurrent

Dimension of shape in conv1D

て烟熏妆下的殇ゞ 提交于 2019-12-17 05:40:17
问题 I have tried to build a CNN with one layer, but I have some problem with it. Indeed, the compilator says me that ValueError: Error when checking model input: expected conv1d_1_input to have 3 dimensions, but got array with shape (569, 30) This is the code import numpy from keras.models import Sequential from keras.layers.convolutional import Conv1D numpy.random.seed(7) datasetTraining = numpy.loadtxt("CancerAdapter.csv",delimiter=",") X = datasetTraining[:,1:31] Y = datasetTraining[:,0]

Dimension of shape in conv1D

旧城冷巷雨未停 提交于 2019-12-17 05:40:00
问题 I have tried to build a CNN with one layer, but I have some problem with it. Indeed, the compilator says me that ValueError: Error when checking model input: expected conv1d_1_input to have 3 dimensions, but got array with shape (569, 30) This is the code import numpy from keras.models import Sequential from keras.layers.convolutional import Conv1D numpy.random.seed(7) datasetTraining = numpy.loadtxt("CancerAdapter.csv",delimiter=",") X = datasetTraining[:,1:31] Y = datasetTraining[:,0]

expected dense_1 to have 2 dimensions, but got array with shape (308, 1, 6)

可紊 提交于 2019-12-14 03:53:44
问题 I'm trying to use Conv1D for the first time for multiclass classification of time series data and my model keeps throwing this error when I use it. import numpy as np import os import keras from keras.models import Sequential from keras.layers import Conv1D, Dense, TimeDistributed, MaxPooling1D, Flatten # fix random seed for reproducibility np.random.seed(7) dataset1 = np.genfromtxt(os.path.join('data', 'norm_cellcycle_384_17.txt'), delimiter=',', dtype=None) data = dataset1[1:] # extract

Keras' convolution layer on images coming from circular/cyclic domain [closed]

五迷三道 提交于 2019-12-14 03:46:55
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 8 months ago . The Need Hello, I am experimenting the usage of CNNs on images which come from a cylindric domain , so I am interested to apply the Convolution layer in a circular (or cyclic) way. I mean a convolution layer that instead of padding the image with zeros would just wrap around the

LSTM Keras- Value input dimension error

北城以北 提交于 2019-12-14 03:13:24
问题 I am trying to implement LSTM using Keras for a multi class problem. I have input csv of dimension 1007x5. number of features per instances are 5 and there are total 12 classes. Below is the code seed = 7 numpy.random.seed(seed) input_file = 'input.csv' def load_data(test_split = 0.2): print ('Loading data...') dataframe = pandas.read_csv(input_file, header=None) dataset = dataframe.values X = dataset[:,0:5].astype(float) print(X) Y = dataset[:,5] print("y=", Y) return X,Y def create_model(X)

Theano / Keras: Set the K-first values of Tensor to a value

断了今生、忘了曾经 提交于 2019-12-13 17:16:42
问题 I have a custom Keras layer and i use Theano as the backend and i want to do the following operation: Suppose we have a tensor with shape (N,). I want to set the K first values to a fixed value x (3 or whatever...). How do i do that? I assume i have to use argsort but i don't know how to implement it using Theano. For example in a simple FF layer, how can i set the first N values of the tensor a to a value x ? def call(self, x, mask=None): a = K.dot(x, self.W) if self.bias: a += self.b return

Keras TimeDistributed Conv1D Error

旧街凉风 提交于 2019-12-13 12:35:28
问题 This is my code: cnn_input = Input(shape=(cnn_max_length,)) emb_output = Embedding(num_chars + 1, output_dim=32, input_length=cnn_max_length, trainable=True)(cnn_input) output = TimeDistributed(Convolution1D(filters=128, kernel_size=4, activation='relu'))(emb_output) I want to train a character-level CNN sequence labeler and I keep receiving this error: Traceback (most recent call last): File "word_lstm_char_cnn.py", line 24, in <module> output = kl.TimeDistributed(kl.Convolution1D(filters

keras (lstm) - necessary shape when using return_sequences=True

烂漫一生 提交于 2019-12-13 03:02:32
问题 I am trying to fit an LSTM network to a sin function. Currently, as far as I understand Keras, my code does only predict the next value. According to this link: Many to one and many to many LSTM examples in Keras it is a many to one model. However, my goal is to implement a Many-to-many model. Basically, I want to be able to predict let's say 10 values, to a given time. When I am trying to use return_sequences=True (see line model.add(..) ), which is supposed to be the solution, the following