本文整理汇总了Python中utils.blob.im_list_to_blob函数的典型用法代码示例。如果您正苦于以下问题:Python im_list_to_blob函数的具体用法?Python im_list_to_blob怎么用?Python im_list_to_blob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了im_list_to_blob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, sample):
# resizes image and returns scale factors
original_im_size=sample['image'].shape
im_list,im_scales = prep_im_for_blob(sample['image'],
pixel_means=self.mean,
target_sizes=self.target_sizes,
max_size=self.max_size)
sample['image'] = torch.FloatTensor(im_list_to_blob(im_list,self.fpn_on)) # im_list_to blob swaps channels and adds stride in case of fpn
sample['scaling_factors'] = im_scales[0]
sample['original_im_size'] = torch.FloatTensor(original_im_size)
if len(sample['dbentry']['boxes'])!=0 and not self.sample_proposals_for_training: # Fast RCNN test
proposals = sample['dbentry']['boxes']*im_scales[0]
if self.remove_dup_proposals:
proposals,_ = self.remove_dup_prop(proposals)
if self.fpn_on==False:
sample['rois'] = torch.FloatTensor(proposals)
else:
multiscale_proposals = add_multilevel_rois_for_test({'rois': proposals},'rois')
for k in multiscale_proposals.keys():
sample[k] = torch.FloatTensor(multiscale_proposals[k])
elif self.sample_proposals_for_training: # Fast RCNN training
sampled_rois_labels_and_targets = fast_rcnn_sample_rois(roidb=sample['dbentry'],
im_scale=im_scales[0],
batch_idx=0) # ok as long as we keep batch_size=1
sampled_rois_labels_and_targets = {key: torch.FloatTensor(value) for key,value in sampled_rois_labels_and_targets.items()}
# add to sample
sample = {**sample, **sampled_rois_labels_and_targets}
# remove dbentry from sample
del sample['dbentry']
return sample
示例2: _get_image_blob
def _get_image_blob(roidb):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
# Sample random scales to use for each image in this batch
scale_inds = np.random.randint(
0, high=len(cfg.TRAIN.SCALES), size=num_images)
processed_ims = []
im_scales = []
for i in range(num_images):
im = cv2.imread(roidb[i]['image'])
assert im is not None, \
'Failed to read image \'{}\''.format(roidb[i]['image'])
# If NOT using opencv to read in images, uncomment following lines
# if len(im.shape) == 2:
# im = im[:, :, np.newaxis]
# im = np.concatenate((im, im, im), axis=2)
# # flip the channel, since the original one using cv2
# # rgb -> bgr
# im = im[:, :, ::-1]
if roidb[i]['flipped']:
im = im[:, ::-1, :]
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = blob_utils.prep_im_for_blob(
im, cfg.PIXEL_MEANS, [target_size], cfg.TRAIN.MAX_SIZE)
im_scales.append(im_scale[0])
processed_ims.append(im[0])
# Create a blob to hold the input images [n, c, h, w]
blob = blob_utils.im_list_to_blob(processed_ims)
return blob, im_scales
示例3: _get_image_blob
def _get_image_blob(roidb, scale_inds):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
processed_ims = []
im_scales = []
for i in xrange(num_images):
if cfg.TRAIN.IS_COLOR == True:
im = cv2.imread(roidb[i]['image'])
if roidb[i]['flipped']:
im = im[:, ::-1, :]
else:
im = cv2.imread(roidb[i]['image'], flags= cv2.CV_LOAD_IMAGE_GRAYSCALE)
#im = cv2.cvtColor(gim, cv2.COLOR_GRAY2BGR)
if roidb[i]['flipped']:
im = im[:, ::-1]
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size,
cfg.TRAIN.MAX_SIZE)
im_scales.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, im_scales
示例4: _get_image_blob
def _get_image_blob(roidb):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
# Sample random scales to use for each image in this batch
scale_inds = np.random.randint(
0, high=len(cfg.TRAIN.SCALES), size=num_images
)
processed_ims = []
im_scales = []
for i in range(num_images):
im = cv2.imread(roidb[i]['image'])
if roidb[i]['flipped']:
im = im[:, ::-1, :]
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = blob_utils.prep_im_for_blob(
im, cfg.PIXEL_MEANS, [target_size], cfg.TRAIN.MAX_SIZE
)
im_scales.append(im_scale[0])
processed_ims.append(im[0])
# Create a blob to hold the input images
blob = blob_utils.im_list_to_blob(processed_ims)
return blob, im_scales
示例5: _get_image_blob
def _get_image_blob(roidb, scale_inds):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
processed_ims = []
im_scales = []
for i in xrange(num_images):
im_bgr = cv2.imread(roidb[i]['image'])
if cfg.DEBUG:
print im_bgr.shape
#******************************
# Add deformed mask to input
#******************************
deformed_mask = cv2.imread(roidb[i]['deformed_mask'],0)
im = np.zeros((im_bgr.shape[0], im_bgr.shape[1], 4))
im[:,:,0:3] = im_bgr
im[:,:,3] = deformed_mask
if roidb[i]['flipped']:
im = im[:, ::-1, :]
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size,
cfg.TRAIN.MAX_SIZE)
im_scales.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, im_scales
示例6: _get_image_blob
def _get_image_blob(im):
"""Converts an image into a network input.
Arguments:
im (list of ndarray): a list of color images in BGR order. In case of
video it is a list of frames, else is is a list with len = 1.
Returns:
blob (ndarray): a data blob holding an image pyramid (or video pyramid)
im_scale_factors (ndarray): array of image scales (relative to im) used
in the image pyramid
"""
all_processed_ims = [] # contains a a list for each frame, for each scale
all_im_scale_factors = []
for frame in im:
processed_ims, im_scale_factors = blob_utils.prep_im_for_blob(
frame, cfg.PIXEL_MEANS, cfg.TEST.SCALES, cfg.TEST.MAX_SIZE)
all_processed_ims.append(processed_ims)
all_im_scale_factors.append(im_scale_factors)
# All the im_scale_factors will be the same, so just take the first one
for el in all_im_scale_factors:
assert(all_im_scale_factors[0] == el)
im_scale_factors = all_im_scale_factors[0]
# Now get all frames with corresponding scale next to each other
processed_ims = []
for i in range(len(all_processed_ims[0])):
for frames_at_specific_scale in all_processed_ims:
processed_ims.append(frames_at_specific_scale[i])
# Now processed_ims contains
# [frame1_scale1, frame2_scale1..., frame1_scale2, frame2_scale2...] etc
blob = blob_utils.im_list_to_blob(processed_ims)
return blob, np.array(im_scale_factors)
示例7: _get_image_blob
def _get_image_blob(roidb, scale_inds):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
processed_ims = []
im_scales = []
for i in xrange(num_images):
im = cv2.imread(roidb[i]['image'])
if roidb[i]['flipped']:
im = im[:, ::-1, :]
im_orig = im.astype(np.float32, copy=True)
im_orig -= cfg.PIXEL_MEANS
im_scale = cfg.TRAIN.SCALES_BASE[scale_inds[i]]
im = cv2.resize(im_orig, None, None, fx=im_scale, fy=im_scale, interpolation=cv2.INTER_LINEAR)
im_scales.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, im_scales
示例8: _get_image_blob
def _get_image_blob(roidb, scale_inds):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
processed_ims = []
im_scales = []
for i in xrange(num_images):
#im = cv2.imread(roidb[i]['image'])
#Multi channels supported
im = np.load(roidb[i]['image'])
if im.ndim != 3:
im = np.expand_dims(im, axis=2)
if roidb[i]['flipped']:
im = im[:, ::-1, :]
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size,
cfg.TRAIN.MAX_SIZE)
im_scales.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, im_scales
示例9: _get_image_blob
def _get_image_blob(roidb, scale_inds, data_i):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
processed_ims = []
im_scales = []
for i in xrange(num_images):
imname1 = roidb[i]["image"][data_i]
imname2 = imname1 + "_norm.png"
im1 = cv2.imread(imname1)
im2 = cv2.imread(imname2)
if roidb[i]["flipped"]:
im1 = im1[:, ::-1, :]
im2 = im2[:, ::-1, :]
im2[:, :, 2] = 255 - im2[:, :, 2]
im = np.zeros((im1.shape[0], im1.shape[1], 6))
im = im.astype("uint8")
im1 = im1[:, :, ::-1]
im2 = im2[:, :, ::-1]
im[:, :, 0:3] = im1
im[:, :, 3:6] = im2
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = prep_im_for_blob(im, 127.5, target_size, cfg.TRAIN.MAX_SIZE)
im_scales.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, im_scales
示例10: _get_rprocessed_image_blob
def _get_rprocessed_image_blob(roidb, scale_inds, angles):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
processed_ims = []
im_scales = []
for i in xrange(num_images):
im = cv2.imread(roidb[i]['image'])
if roidb[i]['flipped']:
im = im[:, ::-1, :]
if roidb[i]['rotated']:
# get the size of image
(h, w) = im.shape[:2]
# set the rotation center
center = (w / 2, h / 2)
# get the rotation matrix no scale changes
scale = 1.0
# anti-clockwise angle in the function
M = cv2.getRotationMatrix2D(center, angles[i], scale)
im = cv2.warpAffine(im,M,(w,h))
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size,
cfg.TRAIN.MAX_SIZE)
im_scales.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, im_scales
示例11: _get_image_blob
def _get_image_blob(im):
"""Converts an image into a network input.
Arguments:
im (ndarray): a color image in BGR order
Returns:
blob (ndarray): a data blob holding an image pyramid
im_scale_factors (list): list of image scales (relative to im) used
in the image pyramid
"""
im_orig = im.astype(np.float32, copy=True)
im_orig -= cfg.PIXEL_MEANS
processed_ims = []
assert len(cfg.TEST.SCALES_BASE) == 1
im_scale = cfg.TRAIN.SCALES_BASE[0]
im = cv2.resize(im_orig, None, None, fx=im_scale, fy=im_scale,
interpolation=cv2.INTER_LINEAR)
im_info = np.hstack((im.shape[:2], im_scale))[np.newaxis, :]
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, im_info
示例12: _get_image_blob
def _get_image_blob(im):
"""Converts an image into a network input.
Arguments:
im (ndarray): a color image in BGR order
Returns:
blob (ndarray): a data blob holding an image pyramid
im_scale_factors (list): list of image scales (relative to im) used
in the image pyramid
"""
im_orig = im.astype(np.float32, copy=True)
im_orig -= cfg.PIXEL_MEANS
processed_ims = []
im_scale_factors = []
scales = cfg.TEST.SCALES_BASE
for im_scale in scales:
im = cv2.resize(im_orig, None, None, fx=im_scale, fy=im_scale, interpolation=cv2.INTER_LINEAR)
im_scale_factors.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, np.array(im_scale_factors)
示例13: _get_image_blob
def _get_image_blob(im):
"""Converts an image into a network input.
Arguments:
im (ndarray): a color image in BGR order
Returns:
blob (ndarray): a data blob holding an image pyramid
im_scale_factors (list): list of image scales (relative to im) used
in the image pyramid
"""
im_orig = im.astype(np.float32, copy=True)
im_orig -= cfg.PIXEL_MEANS
im_shape = im_orig.shape
im_size_min = np.min(im_shape[0:2])
im_size_max = np.max(im_shape[0:2])
processed_ims = []
im_scale_factors = []
for target_size in cfg.TEST.SCALES:
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) > cfg.TEST.MAX_SIZE:
im_scale = float(cfg.TEST.MAX_SIZE) / float(im_size_max)
im = cv2.resize(im_orig, None, None, fx=im_scale, fy=im_scale,
interpolation=cv2.INTER_LINEAR)
im_scale_factors.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, np.array(im_scale_factors)
示例14: _get_image_blob
def _get_image_blob(imdb, roidb, scale_inds):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
processed_ims = []
im_scales = []
for i in xrange(num_images):
proto = imdb.get_proto_at(roidb[i]['image'])
mem = BytesIO(proto.data)
im = io.imread(mem)
im = im[:,:,::-1]
if roidb[i]['flipped']:
im = im[:, ::-1, :]
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size,
cfg.TRAIN.MAX_SIZE, cfg.TRAIN.SCALE_MULTIPLE_OF)
im_scales.append(im_scale)
processed_ims.append(im)
# Create a blob to hold the input images
blob = im_list_to_blob(processed_ims)
return blob, im_scales
示例15: _get_image_blob
def _get_image_blob(roidb):
"""Builds an input blob from the images in the roidb at the specified
scales.
"""
num_images = len(roidb)
# Sample random scales to use for each image in this batch
scale_inds = np.random.randint(
0, high=len(cfg.TRAIN.SCALES), size=num_images)
processed_ims = []
im_scales = []
for i in range(num_images):
ims = image_utils.read_image_video(roidb[i])
for im_id, im in enumerate(ims):
if roidb[i]['flipped']:
im = im[:, ::-1, :]
target_size = cfg.TRAIN.SCALES[scale_inds[i]]
im, im_scale = blob_utils.prep_im_for_blob(
im, cfg.PIXEL_MEANS, [target_size], cfg.TRAIN.MAX_SIZE)
ims[im_id] = im[0]
# Just taking the im_scale for the last im in ims is fine (all are same)
im_scales.append(im_scale[0])
processed_ims += ims
# Create a blob to hold the input images
blob = blob_utils.im_list_to_blob(processed_ims)
return blob, im_scales