def load_minibatch(input_list, color, labels, start,num):
# Enforce maximum on start
start = max(0,start)
# Enforce minimum on end
end = start + num
end = min(len(input_list), end)
# Isolate files
files = input_list[start:end]
images = []
for file in files:
img = caffe.io.load_image(file, color)
# Handle incorrect image dims for uncropped images
# TODO: Get uncropped images to import correctly
if img.shape[0] == 3 or img.shape[0] == 1:
img = np.swapaxes(np.swapaxes(img, 0, 1), 1, 2)
# BUG FIX: Is this ok?
# color=True gets the correct desired dimension of WxHx3
# But color=False gets images of WxHx1. Need WxHx3 or will get "Index out of bounds" exception
# Fix by concatenating three copies of the image
if img.shape[2] == 1:
img = cv.merge([img,img,img])
# Add image array to batch
images.append(img)
labelsReduced = labels[start:end]
return images, labelsReduced
# Classify all images in a list of image file names
# No return value, but can display outputs if desired
caffe_functions.py 文件源码
python
阅读 22
收藏 0
点赞 0
评论 0
评论列表
文章目录