Training Network with sub networks - neural-network

I am planning to train the following network from end-to-end. I have two questions:
Question 1
I have 4 ground truths.
Segmentation of distorted images
Parameters
Corrected images
Segmentation of corrected images
My problem is that as it can be seen in the image, The first two outputs are from network 1 and 2 and the last 2 from network 3.
Is there any way I can train my network from end to end.
Question 2
How can I load the VGG network weights.
I have connections from middle layers to Network 2 and subnetwork 1-2.
I am using Tensorflow 2.4.1

Related

Autoencoder with Multiple Outputs

How do I make an autoencoder with 2 different images at the output layer? I am asked to average 2 images as input to a neural network and receive both images separately as output.

how is the dimension of the activation being as an input to the pooling layer

I am using alexnet, you can see the structure of the network as following:
Alexnet structure with outputs
I used the activations function in Matlab to get the features of my data from the output of conv5 layer. The output is a feature vector with a dimension 43264 for each single image (I have 14000 Images).
I did some processing on this output with no change in the dimension so it still 43264.
I want to re-enter the data to the network starting in pooling layer 5 and train the network.
As you can notice in the structure of alexnet, the input of the pooling 5 should be 13x13x256. So I changed the feature vector 43264 to 13x13x256 matrix, so the whole training set will be a cell array 14000x1 each cell has 13x13x256.
I used the following code to train the network:
net = trainNetwork (Trainingset, labels, Layers, trainingOptions)
I still has an error saying unexpected input to Pooling layer!
Any I idea please?
Thanks in advance
Many Thanks

Why do we need layers in artificial neural network?

I am quite new to artificial neural network, and what I cannot understand is why we need the concept of layer.
Isn't is enough to connect each neuron to some other neurons creating a kind of web more then a layered based structure?
For example for solving the XOR we usually need at least 3 layers, 1 input with 2 neurons, 1+ hidden layer(s) with some neurons and 1 output layer with 1 neuron.
Couldn't we create a network with 2 input neurons (we need them) and 1 output connected by a web of other neurons?
Example of what I mean
The term 'layer' is different than you might think. There is always a 'web' of neurons. A layer just denotes a group of neurons.
If I want to connect layer X with layer Y, this means I am connecting all neurons from layer X to all neurons from layer Y. But not always! You could also connect each neuron from layer X to just one neuron in layer Y. There are lots of different connection techniques.
But layers aren't required! It just makes the coding (and explanation) process a whole lot easier. Instead of connecting all neurons one by one, you can connect them in layers. It's far easier to say "layer A and B are connected" than "neuron 1,2,3,4,5 are all connected with neurons 6,7,8,9".
If you are interested in 'layerless' networks, please take a look at Liquid State Machines:
(the neurons might look to be layered, but they aren't!)
PS: I develop a Javascript neural network library, and I have created an onlinedemo in which a neural network evolves to an XOR gate - without layers, just starting with input and output. View it here.. Your example picture is exactly what kind of networks you could develop with this library.

how to train 1000 neural networks using GPU in Matlab simultaneously?

everyone!
I tried to use
parfor i = 1 : 1000
net{i} = train(net_sample, x, t,'useGPU','yes');
end;
but it failed.
Is there any way to teach them simultaneously?
Is there any code for other programming language to train multiple networks simultaneously?
For simple example,
let's assume that We have network which contains 2 x 2 x 1 neurons and takes 10 input train vectors 5 x 1.
If you don't have more than one GPU, there's just no point in doing this. Every worker in your pool is competing for the same resources, and if your network is anything more than trivially small the GPU will be fully utilized so you can't even get any benefit out of using MPS.

Why are inputs for convolutional neural networks always squared images?

I have been doing deep learning with CNN for a while and I realize that the inputs for a model are always squared images.
I see that neither convolution operation or neural network architecture itself require such property.
So, what is the reason for that?
Because square images are pleasing to the eye. But there are applications on non-square images when domain requires it. For instance SVHN original dataset is an image of several digits, and hence rectangular images are used as input to convnet, as here
From Suhas Pillai:
The problem is not with convolutional layers, it's the fully connected
layers of the network ,which require fix number of neurons.For
example, take a small 3 layer network + softmax layer. If first 2
layers are convolutional + max pooling, assuming the dimensions are
same before and after convolution, and pooling reduces dim/2 ,which is
usually the case. For an image of 3*32*32(C,W,H)with 4 filters in the
first layer and 6 filters in the second layer ,the output after
convolutional + max pooling at the end of 2nd layer, will be 6*8*8
,whereas for an image with 3*64*64, at the end of 2nd layer output
will be 6*16*16. Before doing fully connected,we stretch this as a
single vector( 6*8*8=384 neurons)and do a fully connected operation.
So, you cannot have different dimension fully connected layers for
different size images. One way to tackle this is using spatial pyramid
pooling, where you force the output of last convolutional layer to
pool it to a fixed number of bins(I.e neurons) such that fully
connected layer has same number of neurons. You can also check fully
convolutional networks, which can take non-square images.
It is not necessary to have squared images. I see two "reasons" for it:
scaling: If images are scaled automatically from another aspect ratio (and landscape / portrait mode) this in average might introduce the least error
publications / visualizations: square images are easy to display together