Tensorflow version Faster RCNN source parsing (TFFRCNN) (7) utils / blob.py

This blog is on github CharlesShang / TFFRCNN version of the source code for parsing Series Notes

--------------- personal study notes ---------------

---------------- The author Wu Jiang --------------

------ Click here to link to the original blog Park ------

 

1.im_list_to_blob (ims) function

Ims list structure is composed of a plurality of images as input network blob, the blob dimension (the number of images, max_shape [0], max_shape [ 1], 3), to be noted that the list of the image subject to image incoming Save the mean image, BGR conversion process

DEF im_list_to_blob (IMS):
     # the list of images constituting the input network configuration blob 
    "" " . A List of the Convert Images INPUT INTO A Network 
    . Assumes Images are already Prepared (Subtracted means, the BGR Order, ...) 
    " "" 
    max_shape = np.array ([im.shape for IM in IMS]). max (Axis = 0)   # remove max_shape maximum image Shape [0], max_shape [. 1] 
    NUM_IMAGES = len (IMS)
     # configured blob input dimension (the number of images, max_shape [0], max_shape [. 1],. 3) 
    BLOB np.zeros = ((NUM_IMAGES, max_shape [0], max_shape [. 1],. 3 ), 
                    DTYPE = np.float32)
     for I in xrange(num_images):
        im = ims[i]
        blob[i, 0:im.shape[0], 0:im.shape[1], :] = im
    return blob
# -*- coding:utf-8 -*-
# Author: WUJiang
# 测试功能

import numpy as np

max_shape = np.array([(1, 2, 3), (2, 1, 3)]).max(axis=0)
# [2, 2, 3]
print(max_shape)
View Code

2.prep_im_for_blob(im,pixel_means,target_size,max_size)

On the image by one minus the mean , the scaling processing for image data configured as a network input blob

def prep_im_for_blob(im, pixel_means, target_size, max_size):
    # 为构造blob网络输入对图像预处理,包括减去均值、缩放
    """Mean subtract and scale an image for use in a blob."""
    im = im.astype(np.float32, copy=False)
    im -= pixel_means
    im_shape = im.shape
    im_size_min = np.min(im_shape[0:2])
    im_size_max = np.max(im_shape[0:2])
    im_scale = float(target_size) / float(im_size_min)
    # Prevent the biggest axis from being more than MAX_SIZE
    if np.round(im_scale * im_size_max) >MAX_SIZE: 
        im_scale = a float (MAX_SIZE) / a float (im_size_max)
     # randomized downsampling 
    # Default TRAIN.RANDOM_DOWNSAMPLE = False, the training phase using a random sample without 
    IF cfg.TRAIN.RANDOM_DOWNSAMPLE: 
        R & lt = 0.6 + np.random.rand () 0.4 * 
        im_scale * = R & lt 
    IM = cv2.resize (IM, None, None, im_scale = FX, FY = im_scale, 
                    interpolation = cv2.INTER_LINEAR)
     return IM, im_scale

Guess you like

Origin www.cnblogs.com/deeplearning1314/p/11284176.html