Skip to content

Commit

Permalink
fixed SetOverlayAlpha() issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dusty-nv committed Sep 14, 2020
1 parent 610e2c5 commit d54eb0c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
15 changes: 14 additions & 1 deletion c/segNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ segNet::segNet() : tensorNet()
mLastInputHeight = 0;
mLastInputFormat = IMAGE_UNKNOWN;

mColorsAlphaSet = NULL;
mClassColors[0] = NULL; // cpu ptr
mClassColors[1] = NULL; // gpu ptr

Expand Down Expand Up @@ -382,6 +383,16 @@ segNet* segNet::Create( const char* prototxt, const char* model, const char* lab
net->mClassColors[0][n*4+3] = 255.0f; // a
}

net->mColorsAlphaSet = (bool*)malloc(numClasses * sizeof(bool));

if( !net->mColorsAlphaSet )
{
printf(LOG_TRT "segNet -- failed to allocate class colors alpha flag array\n");
return NULL;
}

memset(net->mColorsAlphaSet, 0, numClasses * sizeof(bool));

// initialize array of classified argmax
const int s_w = DIMS_W(net->mOutputs[0].dims);
const int s_h = DIMS_H(net->mOutputs[0].dims);
Expand Down Expand Up @@ -620,6 +631,8 @@ void segNet::SetClassColor( uint32_t classIndex, float r, float g, float b, floa
mClassColors[0][i+1] = g;
mClassColors[0][i+2] = b;
mClassColors[0][i+3] = a;

mColorsAlphaSet[classIndex] = (a == 255) ? false : true;
}


Expand All @@ -630,7 +643,7 @@ void segNet::SetOverlayAlpha( float alpha, bool explicit_exempt )

for( uint32_t n=0; n < numClasses; n++ )
{
if( !explicit_exempt || mClassColors[0][n*4+3] == 255 )
if( !explicit_exempt || !mColorsAlphaSet[n] /*mClassColors[0][n*4+3] == 255*/ )
mClassColors[0][n*4+3] = alpha;
}
}
Expand Down
5 changes: 3 additions & 2 deletions c/segNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* Default alpha blending value used during overlay
* @ingroup segNet
*/
#define SEGNET_DEFAULT_ALPHA 120
#define SEGNET_DEFAULT_ALPHA 150

/**
* Standard command-line options able to be passed to segNet::Create()
Expand All @@ -69,7 +69,7 @@
" --input-blob=INPUT name of the input layer (default: '" SEGNET_DEFAULT_INPUT "')\n" \
" --output-blob=OUTPUT name of the output layer (default: '" SEGNET_DEFAULT_OUTPUT "')\n" \
" --batch-size=BATCH maximum batch size (default is 1)\n" \
" --alpha=ALPHA overlay alpha blending value, range 0-255 (default: 120)\n" \
" --alpha=ALPHA overlay alpha blending value, range 0-255 (default: 150)\n" \
" --visualize=VISUAL visualization flags (e.g. --visualize=overlay,mask)\n" \
" valid combinations are: 'overlay', 'mask'\n" \
" --profile enable layer profiling in TensorRT\n\n"
Expand Down Expand Up @@ -363,6 +363,7 @@ class segNet : public tensorNet
std::vector<std::string> mClassLabels;
std::string mClassPath;

bool* mColorsAlphaSet; /**< true if class color had been explicitly set from file or user */
float* mClassColors[2]; /**< array of overlay colors in shared CPU/GPU memory */
uint8_t* mClassMap[2]; /**< runtime buffer for the argmax-classified class index of each tile */

Expand Down
Binary file modified data/images/dog_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/images/dog_4.jpg
Binary file not shown.
Binary file removed data/images/dog_5.jpg
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/segnet/segnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int main( int argc, char** argv )
}

// set alpha blending value for classes that don't explicitly already have an alpha
net->SetOverlayAlpha(cmdLine.GetFloat("alpha", 180.0f));
net->SetOverlayAlpha(cmdLine.GetFloat("alpha", 150.0f));

// get the desired overlay/mask filtering mode
const segNet::FilterMode filterMode = segNet::FilterModeFromStr(cmdLine.GetString("filter-mode", "linear"));
Expand Down
2 changes: 1 addition & 1 deletion python/examples/segnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
parser.add_argument("--filter-mode", type=str, default="linear", choices=["point", "linear"], help="filtering mode used during visualization, options are:\n 'point' or 'linear' (default: 'linear')")
parser.add_argument("--visualize", type=str, default="overlay,mask", help="Visualization options (can be 'overlay' 'mask' 'overlay,mask'")
parser.add_argument("--ignore-class", type=str, default="void", help="optional name of class to ignore in the visualization results (default: 'void')")
parser.add_argument("--alpha", type=float, default=175.0, help="alpha blending value to use during overlay, between 0.0 and 255.0 (default: 175.0)")
parser.add_argument("--alpha", type=float, default=150.0, help="alpha blending value to use during overlay, between 0.0 and 255.0 (default: 150.0)")
parser.add_argument("--stats", action="store_true", help="compute statistics about segmentation mask class output")

is_headless = ["--headless"] if sys.argv[0].find('console.py') != -1 else [""]
Expand Down

0 comments on commit d54eb0c

Please sign in to comment.