Skip to content

infer and preproc a grayscale model#379

Open
Rtms1984 wants to merge 1 commit into
TexasInstruments:developfrom
Rtms1984:grayscale-model-inference
Open

infer and preproc a grayscale model#379
Rtms1984 wants to merge 1 commit into
TexasInstruments:developfrom
Rtms1984:grayscale-model-inference

Conversation

@Rtms1984

@Rtms1984 Rtms1984 commented Jun 3, 2026

Copy link
Copy Markdown

Add grayscale model preprocessing and inference support

@Rtms1984

Rtms1984 commented Jun 4, 2026

Copy link
Copy Markdown
Author

Across the three elements, no new user-facing properties were added — the changes are all internal plumbing to support a new GRAY8 / single-channel path (preproc elements) and to handle 4-D model outputs more correctly (inferer).

tiovxdlpreproc

  • Sink caps: adds GRAY8 to TIOVX_DL_PRE_PROC_SUPPORTED_FORMATS_SINK
  • New struct field gboolean gray8_cpu_bypass
  • init_module: for GRAY8 input, output tensor channel count is forced to 1 and the bypass flag is enabled
  • New transform override that, in bypass mode, does CPU (pixel-mean)*scale → float32, copies timestamps, and skips the TIOVX kernel (Could not add grayscale support since the code is closed source).
  • No new GObject properties. Existing scale-* / mean-* are reused; only scale[0]/mean[0] matter in the GRAY8 path.

tidlpreproc

  • Sink caps: {RGB, NV12} → {RGB, NV12, GRAY8}
  • New struct field gint num_channels on _GstTIDLPreProc, default 3
  • parse_model now also extracts the channel count from the model's input tensor shape and bumps the NCHW shape size check from >=3 to >=4 and NHWC from >=2 to >=3.
  • New GRAY8 branch in transform: per-pixel (v - mean[0]) * scale[0] with a switch over tensor_data_type writing int8/uint8/int16/uint16/int32/uint32/float32 directly into the output tensor, honoring in_stride_y
  • No new GObject properties. Existing props (model, scale-, mean-, channel-order, data-type, tensor-format, out-pool-size) are unchanged.

tidlinferer

  • New struct field guint input_channels on _GstTIDLInferer, populated in transform_caps for both NHWC/NCHW layouts. It's tracked internally but not yet exposed as a property or in caps.

  • Set_output_params reworked:

  1. Adds a special-case for dim == 4 outputs: current_height = shape[2], current_width = shape[1] * shape[3]. The previous "first two non-1 dims" heuristic is kept only as the fallback for non-4D outputs.
  2. transform_caps fixation now also explicitly fixates num-dims to NUM_TENSOR_DIMS on both src and sink directions.
  3. No new GObject properties. Existing: model, in-pool-size, out-pool-size, debug-level, plus target when ENABLE_TIDL.

@cshilwant

cshilwant commented Jun 11, 2026

Copy link
Copy Markdown
Member

@Rtms1984

Thanks for the pull request! I have a couple of minor comments before we can go ahead and integrate the change:

  1. Could you please add a Signed-off-by tag to your commit message? You can easily do this by amending your commit using git commit -s --amend and force-pushing.
  2. Update the destination branch: Please change the destination branch of this PR from main to develop.
  3. Can we have some tests logs around how GRAY8 FORMAT was validated for preproc.

Once these are updated, we'll get this merged right away.

Thanks again for your contribution!

@Rtms1984
Rtms1984 force-pushed the grayscale-model-inference branch from 8e6aeac to 5018e33 Compare June 12, 2026 08:14
@Rtms1984
Rtms1984 changed the base branch from main to develop June 12, 2026 08:15
Signed-off-by: talebso <sogand.talebi@sick.se>
@Rtms1984
Rtms1984 force-pushed the grayscale-model-inference branch from 5018e33 to 0b63733 Compare June 15, 2026 05:11
@Rtms1984

Copy link
Copy Markdown
Author

Here is the logs from my tests on a grayscale MobilenetV2 classification model with both tidlpreproc and tiovxdlpreproc.
gst-logs.txt

@reesegrimsley reesegrimsley left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR approved after test-case details provided

@sinha-shreyash sinha-shreyash left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rtms1984 , I have few feedback points after having a look at your PR,

  1. Can you please write a appropriate commit msg which describes the changes you are making in more detail.
  2. Please follow the code convention present across entire repo, changing it for few files does not makes sense to me
  3. I see lot of the crux changes are present in transform code, instead it should be handled in utils under edgeai-apps-utils (just like NV12/RGB image) to have uniformity across the code so that we can find all the preproc related operations under one page.

Comment thread ext/ti/gsttidlinferer.cpp
#include "gst-libs/gst/tiovx/gsttiovxutils.h"

#endif //ENABLE_TIDL
#endif //ENABLE_TIDL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing white spaces

Comment thread ext/ti/gsttidlinferer.cpp
#define ARM_MAX_OUTPUT_WIDTH 1001
#define ARM_MAX_OUTPUT_HEIGHT 1001
#endif // NOT ENABLE_TIDL
#endif // NOT ENABLE_TIDL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing white spaces

Comment thread ext/ti/gsttidlinferer.cpp
gsize
output_size;
#endif //ENABLE_TIDL
#endif //ENABLE_TIDL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing white spaces

Comment thread ext/ti/gsttidlinferer.cpp
#ifdef ENABLE_TIDL
PROP_TARGET,
#endif //ENABLE_TIDL
#endif //ENABLE_TIDL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing white spaces

Comment thread ext/ti/gsttidlinferer.cpp
gst_ti_dl_inferer_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);

static guint

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please maintain the code format we are following across the repository, simply changing it for this file does not makes sense to me

Comment thread ext/ti/gsttidlpreproc.cpp

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please follow the code format followed across entire repo

Comment thread ext/ti/gsttidlpreproc.cpp
&&
self->pre_proc_config->inputTensorShapes[0].size() >= 3) {
if (self->pre_proc_config->inputTensorShapes.size () > 0
&& self->pre_proc_config->inputTensorShapes[0].size () >= 4) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changed to 4 ? should not this be 3 same as NHWC format

Comment thread ext/ti/gsttidlpreproc.cpp
} else if (GST_VIDEO_FORMAT_RGB == GST_VIDEO_FRAME_FORMAT (&in_frame)) {
dlPreProcess_RGB_image (self->pre_proc_image_params);
} else if (GST_VIDEO_FORMAT_GRAY8 == GST_VIDEO_FRAME_FORMAT (&in_frame)) {
/* Single-channel CPU normalization: (pixel - mean) * scale.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not add dlPreProcess_GRAY_image function in edgeai-apps-utils ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow the same code format used across repositories

return TRUE;
}

static

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all this process is handled internally in preproc utils defined in edgeai-apps-utils, should not it be added there instead ?

@cshilwant, please comment more on this part

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants