Semantic Segmentation with SegNet terug naar de inleiding
sementic segmentatie
In sematic segmentatie worden afbeeldingen op pixel nivo geclassificeerd waarbij pixels die een verband met elkaar hebben (op elkaar lijken) een segment vormen.
jetson-inference/build/aarch64/bin/segnet-console.py
De commandline argumenten
De input afbeelding is de te testen afbeelding. In de map image zitten een aantal afbeeldingen geschikt voor sementic segmentation
het segmentatie resultaat.
3) optioneel: --network vlag die verwijst naar het segmentation model. Als default wordt --network="fcn-resnet18-voc" gebruikt.
4) optioneel: --visualize vlag met de mask en overlay mode= (default is: overlay)
5) optioneel: --alfa vlag is de alfa waarde van de kleur in de segmenten. (default alfa=120)
6) optioneel: --filter-mode vlag deze vlag accepteerd point of linair sampling waarde, (default linair)
voorbeelden
1) ./segnet-console.py --network=fcn-resnet18-cityscapes images/city_0.jpg output_city.jpg
2) ./segnet-console.py --network=fcn-resnet18-mhp images/humans_0.jpg output_humans.jpg
3 )./segnet-console.py --network=fcn-resnet18-voc images/object_0.jpg output_object.jpg
4) ./segnet-console.py --network=fcn-resnet18-sun images/room_0.jpg output_room.jpg
De broncode van segnet-console.py
import jetson.inference
import jetson.utils
import argparse
import ctypes
import sys
# parse the command line
parser = argparse.ArgumentParser(description="Segment an image using an semantic segmentation DNN.",
formatter_class=argparse.RawTextHelpFormatter, epilog=jetson.inference.segNet.Usage())
parser.add_argument("file_in", type=str, help="filename of the input image to process")
parser.add_argument("file_out", type=str, default=None, nargs='?', help="filename of the output image to save")
parser.add_argument("--network", type=str, default="fcn-resnet18-voc", help="pre-trained model to load, see below for options")
parser.add_argument("--visualize", type=str, default="overlay", choices=["overlay", "mask"], help="visualization mode for the output image, options are:\n 'overlay' or 'mask' (default: 'overlay')")
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("--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=120.0, help="alpha blending value to use during overlay, between 0.0 and 255.0 (default: 120.0)")
try:
opt = parser.parse_known_args()[0]
except:
print("")
parser.print_help()
sys.exit(0)
# load an image (into shared CPU/GPU memory)
img, width, height = jetson.utils.loadImageRGBA(opt.file_in)
# allocate the output image for the overlay/mask
img_output = jetson.utils.cudaAllocMapped(width * height * 4 * ctypes.sizeof(ctypes.c_float))
# load the segmentation network
net = jetson.inference.segNet(opt.network, sys.argv)
# process the segmentation network
net.Process(img, width, height, opt.ignore_class)
# print out timing info
net.PrintProfilerTimes()
# perform the visualization
if opt.file_out is not None:
if opt.visualize == 'overlay':
net.Overlay(img_output, width, height, opt.filter_mode)
elif opt.visualize == 'mask':
net.Mask(img_output, width, height, opt.filter_mode)
jetson.utils.cudaDeviceSynchronize()
jetson.utils.saveImageRGBA(opt.file_out, img_output, width, height)