How to calculate net-scale-factor and offset

• Hardware Platform (Jetson / GPU) Jetson
• DeepStream Version 6.1
• JetPack Version (valid for Jetson only) 5.0.2
• TensorRT Version
• Issue Type( questions, new requirements, bugs) question


I’m currently working on implementing a detector and classifier in DeepStream, but I’ve encountered a particular problem. My classifier, which is built using TAO and utilizes Efficientnet-B0, performs admirably when used independently outside of the DeepStream environment. However, when I integrate it into the pipeline, I’m experiencing a noticeable decrease in performance. I suspect this issue might be related to the net scale factor and offset. To address this, I plan to fine-tune the net scale factor and offset parameters in a configuration file named “config_infer_secondary.txt” to optimize the classifier’s performance within the DeepStream pipeline. Could you provide guidance on how to accurately set these parameters in that file?

I used following technique but no improvement

for data in data_loader:
     image, _ = data
    for c in range(3):
        channel_mean[c] += image[0, c, :, :].mean()
        channel_std_dev[c] += image[0, c, :, :].std()

channel_mean /= len(train_dataset)
channel_std_dev /= len(train_dataset)

# Calculate unscaled standard deviation and its mean
unscaled_std = channel_std_dev * 255
unscaled_std_mean = unscaled_std.mean()

# Calculate net scale factor and offsets
net_scale_factor = 1 / unscaled_std_mean
offsets = (channel_mean * 255).tolist()

You are using numpy functions, please refer to document. numpy.std — NumPy v1.26 Manual
numpy.mean — NumPy v1.26 Manual

ya but this is what i tried as per my best understanding of this numbers
I am looking for official document which explains how to calculate net-scale-factor and offests

There formula is in Gst-nvinfer — DeepStream 6.3 Release documentation

y = net scale factor*(x-mean)

Thank you for your response
I am looking for formula to calculate net-scale-factor
as per my knowledge this formula shows how the net-scale-factor is used


Please read the document, especially the first two paragraphs.

Sorry I am still confused

The paragraph says “net-scale-factor is the pixel scaling factor specified in the configuration file. It is a float.” but how do I calculate it to include in my configuration file ?

It should be the same as the scale factor used in the preprocessing of the training. Which parameters you used in training, please use the same parameters in inferencing.

in the training mean and std of training data was used
net-scale-factor and offsets are required while DeepStream inference

Thank you

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks

Current DeepStream gst-nvinfer internal preprocessing algorithm does not support deviation for normalization. You may implement by yourself.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.