Not able to find out the documentation to create Image embeddings

Hi team,

I am interested in creating Image embeddings.
The typical way to create such embeddings is to use already trained CNN model, modify the model remove the last layer. We then have to pass the image through the network. The output will be a vector representation of the image.

There is a way to achieve this using python. Gluon pretrained model layer access and usage.

Is there any way we can achieve this using scala?

In MXNet Symbol API you can do the following to access intermediate layers:

internals = model.symbol.get_internals()
output_layer_you_want = internals['output_layer_name']

get_internals() gives a new grouped symbol that contains all the internal outputs of the symbol.

In Scala you can use the equivalent function getInternals() https://github.com/apache/incubator-mxnet/blob/master/scala-package/core/src/main/scala/org/apache/mxnet/Symbol.scala#L111 which calls internally _LIB.MXSymbolGetInternals()

Thanks for the reply. But what I wanted to know was how to featurise given image using the model without last layer.
Equivalent code in keras:
model = ResNet50(input_shape=(224, 224, 3), include_top=False, pooling=‘avg’)
cnn_features = model.predict(image)

What I am doing in scala is:
val (symbol, argParams, auxParams) = Model.loadCheckpoint(“models/resnet50_ssd_model”, 0)
val all_layers = symbol.getInternals()
model_without_last_layer = all_layers.get(“flatten18_output”)

Dont know how to go ahead