Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neural network using both images and numerical inputs

To classify images, we are using a neural network with a few convolutional layers followed by a few fully-connected layers.

The metadata has some numerical information that could help classifying the images. Is there an easy way to input the numerical metadata into the first fully-connected layer, together with the output of the convolutions? Is it possible to implement this using TensorFlow, or even better Keras?

like image 381
Michele Usuelli Avatar asked Sep 05 '25 10:09

Michele Usuelli


1 Answers

You may process the numerical data in another branch and then merge the result with the CNN branch and then pass the merged tensor to a few final dense layers. Here is a general sketch of the solution:

# process image data using conv layers
inp_img = Input(shape=...)
# ...

# process numerical data
inp_num = Input(shape=...)
x = Dense(...)(inp_num)
out_num = Dense(...)(x)

# merge the result with a merge layer such as concatenation
merged = concatenate([out_conv, out_num])
# the rest of the network ...

out = Dense(num_classes, activation='softmax')(...)

# create the model
model = Model([inp_img, inp_num], out)

Surely, to build such a model you need to use Keras Functional API. Therefore, I highly recommend to read the official guide for this purpose.

like image 60
today Avatar answered Sep 08 '25 18:09

today