Hello!
An example described here is excellent and easily trained http://mi.eng.cam.ac.uk/projects/segnet/tutorial.html
For my task requires segmentation of two classes: the background and subject. Man and background.
But I have a problem with the preparation of annotated images (labels), in its own database. As I understand the network sees only color in the gray scale. I create labels using Adobe photoshop so:
Uploading original JPEG image
Superimposed over the original, without a background image in PNG format. Thus creating selection mask.
The sacrificial layer with the image without background PNG image.
Encodes the image to indexed color (3 colors: void 0 0 0, person 192 128 128, transparency alpha channel). This is necessary in order to while painting flowers no new colors or blur.
I produce fill the selected area with mask the above colors: 192 128 228 subject, background 0 0 0)
Then convert the image to RGB PNG 8 bit / chanel mode.
If you submit the following annotated (labels) to the input image network, it displays the following:
F0606 19:20:16.349822 2152 math_functions.cu:123] Check failed: status == CUBLAS_STATUS_SUCCESS (11 vs. 0) CUBLAS_STATUS_MAPPING_ERROR.
Then I proceed as follows:
Skipping my images via this script, that should solve my problems:
!/usr/bin/env python
import os
import numpy as np
from itertools import izip
from argparse import ArgumentParser
from collections import OrderedDict
from skimage.io import ImageCollection, imsave
from skimage.transform import resize
camvid_colors = OrderedDict([
("Animal", np.array([64, 128, 64], dtype=np.uint8)),
("Archway", np.array([192, 0, 128], dtype=np.uint8)),
("Bicyclist", np.array([0, 128, 192], dtype=np.uint8)),
("Bridge", np.array([0, 128, 64], dtype=np.uint8)),
("Building", np.array([128, 0, 0], dtype=np.uint8)),
("Car", np.array([64, 0, 128], dtype=np.uint8)),
("CartLuggagePram", np.array([64, 0, 192], dtype=np.uint8)),
("Child", np.array([192, 128, 64], dtype=np.uint8)),
("Column_Pole", np.array([192, 192, 128], dtype=np.uint8)),
("Fence", np.array([64, 64, 128], dtype=np.uint8)),
("LaneMkgsDriv", np.array([128, 0, 192], dtype=np.uint8)),
("LaneMkgsNonDriv", np.array([192, 0, 64], dtype=np.uint8)),
("Misc_Text", np.array([128, 128, 64], dtype=np.uint8)),
("MotorcycleScooter", np.array([192, 0, 192], dtype=np.uint8)),
("OtherMoving", np.array([128, 64, 64], dtype=np.uint8)),
("ParkingBlock", np.array([64, 192, 128], dtype=np.uint8)),
("Pedestrian", np.array([64, 64, 0], dtype=np.uint8)),
("Road", np.array([128, 64, 128], dtype=np.uint8)),
("RoadShoulder", np.array([128, 128, 192], dtype=np.uint8)),
("Sidewalk", np.array([0, 0, 192], dtype=np.uint8)),
("SignSymbol", np.array([192, 128, 128], dtype=np.uint8)),
("Sky", np.array([128, 128, 128], dtype=np.uint8)),
("SUVPickupTruck", np.array([64, 128, 192], dtype=np.uint8)),
("TrafficCone", np.array([0, 0, 64], dtype=np.uint8)),
("TrafficLight", np.array([0, 64, 64], dtype=np.uint8)),
("Train", np.array([192, 64, 128], dtype=np.uint8)),
("Tree", np.array([128, 128, 0], dtype=np.uint8)),
("Truck_Bus", np.array([192, 128, 192], dtype=np.uint8)),
("Tunnel", np.array([64, 0, 64], dtype=np.uint8)),
("VegetationMisc", np.array([192, 192, 0], dtype=np.uint8)),
("Wall", np.array([64, 192, 0], dtype=np.uint8)),
("Void", np.array([0, 0, 0], dtype=np.uint8))
])
def convert_label_to_grayscale(im):
out = (np.ones(im.shape[:2]) * 255).astype(np.uint8)
for gray_val, (label, rgb) in enumerate(camvid_colors.items()):
match_pxls = np.where((im == np.asarray(rgb)).sum(-1) == 3)
out[match_pxls] = gray_val
assert (out != 255).all(), "rounding errors or missing classes in camvid_colors"
return out.astype(np.uint8)
def make_parser():
parser = ArgumentParser()
parser.add_argument(
'label_dir',
help="Directory containing all RGB camvid label images as PNGs"
)
parser.add_argument(
'out_dir',
help="""Directory to save grayscale label images.
Output images have same basename as inputs so be careful not to
overwrite original RGB labels""")
return parser
if name == 'main':
parser = make_parser()
args = parser.parse_args()
labs = ImageCollection(os.path.join(args.label_dir, "*"))
os.makedirs(args.out_dir)
for i, (inpath, im) in enumerate(izip(labs.files, labs)):
print i + 1, "of", len(labs)
# resize to caffe-segnet input size and preserve label values
resized_im = (resize(im, (360, 480), order=0) * 255).astype(np.uint8)
out = convert_label_to_grayscale(resized_im)
outpath = os.path.join(args.out_dir, os.path.basename(inpath))
imsave(outpath, out)
Then again I try to start training with the converted images. Again a message:
Check failed: status == CUBLAS_STATUS_SUCCESS (11 vs. 0).
Remarkable is that the marked image after the tool takes the network and trained them: https://github.com/kyamagu/js-segment-annotator
But that's not what I need. I do not want to mark up the image manually, I already have cut without PNG image background. Please help me to understand how to convert colors to segnet took them? Maybe hsv?
Here's a link to my data: https://github.com/Maxfashko/CamVid?files=1