Hidden layers within sequential layer after importing model in Keras - import

i have a "simple" problem after loading Keras model.
During training my network has following structure
model.summary()
Output from command line after defining architecture
After training + saving + loading my network appears to have following structure:
Output from command line after loading
Unfortunately I'm unable to find the way to access the sequential layer. My goal is to visualize the feature maps which are within the sequential layer.
I will provide code in case it will be necessary.
Thank you,
Vaclav

Related

Access output of layers inside Core ML Model

I used the Core ML Converter to convert a Caffe AlexNet model to a Core ML model. The model works just fine and outputs correct classification results. However, I do not know how to access the output of a layer inside the CNN model. Say for example I want to know what the output of one of the convolution layer (e.g. conv5) is. Caffe let you do so easily, but I could not find documentation on how to do this using Core ML.
Does Core ML allow access to outputs of layers inside the CNN model like Caffe does?

Change optimizer alghoritm in Keras

If you change the optimizer in Keras, you need to compile your model again. This compilation overrides the learned weights of the network. I know how to save weights, but I do not know how to restore them for a network. Can someone please help?
Here is a YouTube video that explains exactly what you're wanting to do: Save and load a Keras model
How you load the model weights is going to depend on how you saved the model or model weights. There are three different saving methods that Keras makes available. These are described in the video link above (with examples), as well as below.
The model.save('my_model.h5') function saves:
The architecture of the model, allowing to re-create the model.
The weights of the model.
The training configuration (loss, optimizer).
The state of the optimizer, allowing to resume training exactly where you left off.
To load this saved model, you would use the following:
from keras.models import load_model
new_model = load_model('my_model.h5')
The model.to_json() function only saves the architecture of the model. This will not save the weights. To load this saved model, you would use the following:
json_string = model.to_json()
from keras.models import model_from_json
model = model_from_json(json_string)
The model.save_weights('my_model_weights.h5') function only saves the weights of the model. To load these saved weights to a model, you would use the following:
model.load_weights('my_model_weights.h5')

Can I use next layer's output as current layer's input by Keras?

In text generate mission, we usually use model's last output as current input to generate next word. More generalized, I want to achieve a neural network that regards next layer's finally hidden state as current layer's input. Just like the following(what confuses me is the decoder part):
But I have read Keras document and haven't found any functions to achieve it.
Can I achieve this structure by Keras? How?
What you are asking is an autoencoders, you can find similar structures in Keras.
But there are certain details that you should figure it out on your own. Including the padding strategy and preprocessing your input and output data. Your input cannot get dynamic input size, so you need to have a fixed length for input and outputs. I don't know what do you mean by arrows who join in one circle but I guess you can take a look at Merge layer in Keras (basically adding, concatenating, and etc.)
You probably need 4 sequential model and one final model that represent the combined structure.
One more thing, the decoder setup of LSTM (The Language Model) is not dynamic in design. In your model definition, you basically introduce a fixed inputs and outputs for it. Then you prepare the training correctly, so you don't need anything dynamic. Then during the test, you can predict each decoded word in a loop by running the model once predict the next output step and run it again for next time step and so on.
The structure you have showed is a custom structure. So, Keras doesn't provide any class or wrapper to directly build such structure. But YES, you can build this kind of structure in Keras.
So, it looks like you need LSTM model in backward direction. I didn't understand the other part which probably looks like incorporating previous sentence embedding as input to the next time-step input of LSTM unit.
I rather encourage you to work with simple language-modeling with LSTM first. Then you can tweak the architecture later to build an architecture depicted in figure.
Example:
Text generation with LSTM in Keras

Understanding caffe library

I am trying to understand the caffe library. For that I run through step by step for feature_extraction.cpp and classification.cpp.
In those cpp files, I found out layers, prototxt file, caffemodel, net.cpp, caffe.pb.cc, caffe.pb.hfiles.
I know caffe is formed using different layers. So those layer files inside layer folder are used.
prototxt file is meant for the structure of a particular network such as googlenet, alexnet etc. Different net has different structure.
caffemodel is the trained model using caffe library for a specific type of net structure.
What do those net.cpp, caffe.pb.cc do? I mean how to understand their roles in forming this caffe deep learning network.
You understand correctly that caffe implements deep learning by stacking "layers" one on top of the other to form a "net".
'net.cpp'
Each layer works as a "functional block" and its behavior/implementation is defined in src/caffe/layers/<layer>.cpp, src/caffe/layers/<layer>.cu and include/caffe/layers/<layer>.hpp.
The code that actually "stack" all the layers into a net can be found (mostly) in net.cpp.
'caffe.pb.h', 'caffe.pb.cc'
In order to define the specific structure of a specific deep net architecture (e.g., AlexNet, GoogLeNet, ResNet etc.) caffe uses protocol-buffers library. The specific format of caffe protocol buffer is defined in src/caffe/proto/caffe.proto. The caffe.proto is "compiled" using google protobuffer compiler to produce 'caffe.pb.h' and 'caffe.pb.cc' c++ code for parsing and processing caffe prototxt and caffemodel files.

Matlab: specify Neural Net with no hidden layer using built in functions

Most likely a trivial question...how can I create a neural network with no hidden layer for regression problems in Matlab using built in function (I understand this is the same as a multivariate linear regression). My problem set has 5 predictors and one predictand.
I get an error when I try to fit a net with a hidden layer size of 0...i.e.
net=fitnet(0);
Error using fitnet (line 69)
Parameters.hiddenSizes contains a zero.
Second, if I try to call the net using the configure command I also get an error telling me it cannot configure the 'net' since it is a structure.
In short, how can I create a NET object with no hidden layer so that I can train and test it on a set of data predictor and predictand pairs similar to calling a net with a specified number of hidden nodes.
My version of Matlab is R2012a.
Thank you all for your help.
Take a look at the linearnet function, it creates a very simple network of one layer with one neuron.