<jupyter_start><jupyter_text>load_gt_roidb generate bounding box<jupyter_code>### labeling tools
## https://www.reddit.com/r/computervision/comments/5jxhtc/image_segmentation_labelling_tool/
imdb = Cityscape('train', 'data', dataset_path)
roidbs = imdb.gt_roidb()
type(roidbs)
len(roidbs)<jupyter_output><empty_output><jupyter_text>Show Image<jupyter_code>from matplotlib import pyplot as plt
%matplotlib inline
import cv2 as cv
### origin read
import PIL.Image as Image
im = Image.open(roidbs[2]['ins_seg'])
pixel = list(im.getdata())
pixel = np.array(pixel).reshape([im.size[1], im.size[0]])
pixel.min(), pixel.max()
pixel[412, 765]
# [771, 408]
pixel[408, 771]<jupyter_output><empty_output><jupyter_text>image read<jupyter_code>image = cv.imread(roidbs[2]['ins_seg'])
pixel.max()
plt.imshow(image)
image.shape
image.min(), image.max(), image.mean()
roidbs[0]
bbox1 = roidbs[2]['boxes'][6]
center = [(bbox1[0]+bbox1[2])/2, (bbox1[1]+bbox1[3])/2]
center
plt.imshow(image)
plt.plot(center[0], center[1], 'r*')
image[center[1], center[0]]
import matplotlib.patches as patches

fig,ax = plt.subplots(1)

# Display the image
ax.imshow(image)

# Create a Rectangle patch
rect = patches.Rectangle((bbox1[0],bbox1[1]),bbox1[2]-bbox1[0],bbox1[3]-bbox1[1],linewidth=1,edgecolor='r',facecolor='none')

# Add the patch to the Axes
ax.add_patch(rect)

plt.show()<jupyter_output><empty_output><jupyter_text>get_rpn_batch<jupyter_code>from rcnn.io.image import get_image, tensor_vstack
import rcnn.config as config
imgs, roidb = get_image(roidbs[0:10], scale=True)
im_array = tensor_vstack(imgs)
im_array.shape
len(imgs)
 # im_array = np.vstack(imgs)
im_info = []
gt_boxes = []

for im_i in range(len(roidb)):
    im_info.append(roidb[im_i]['im_info'])
        # gt boxes: (x1, y1, x2, y2, cls)
    print im_i, roidb[im_i]['gt_classes'].size
    if roidb[im_i]['gt_classes'].size > 0:
        gt_inds_i = np.where(roidb[im_i]['gt_classes'] != 0)[0]
        gt_boxes_i = np.empty((roidb[im_i]['boxes'].shape[0], 5), dtype=np.float32)
        gt_boxes_i[:, 0:4] = roidb[im_i]['boxes'][gt_inds_i, :]
        gt_boxes_i[:, 4] = roidb[im_i]['gt_classes'][gt_inds_i]
    else:
        gt_boxes_i = np.ones((1, 5), dtype=np.float32) * -1
    gt_boxes.append(gt_boxes_i[np.newaxis, :, :])

im_info = np.array(im_info, dtype=np.float32)
data = {'data': im_array, 'im_info': im_info}
    # gt_boxes shape : [num_images, num_boxes, 5], type list
label = {'gt_boxes': gt_boxes}

label['gt_boxes']
data['im_info']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17679777512912198, 'fraction_numerical': 0.03218116805721097, 'mean_word_length': 6.1737891737891735, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '190221', 'license': 'Apache-2.0', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1063, 'n_words': 171, 'path': 'testMaskRCNN.ipynb', 'repo_name': 'dragonfly90/mask-product', 'size': '2517'}