本文整理汇总了Python中yolo3.utils.letterbox_image方法的典型用法代码示例。如果您正苦于以下问题:Python utils.letterbox_image方法的具体用法?Python utils.letterbox_image怎么用?Python utils.letterbox_image使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yolo3.utils
的用法示例。
在下文中一共展示了utils.letterbox_image方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_training_data
# 需要导入模块: from yolo3 import utils [as 别名]
# 或者: from yolo3.utils import letterbox_image [as 别名]
def get_training_data(annotation_path, data_path, input_shape, max_boxes=100, load_previous=True):
'''processes the data into standard shape
annotation row format: image_file_path box1 box2 ... boxN
box format: x_min,y_min,x_max,y_max,class_index (no space)
'''
if load_previous==True and os.path.isfile(data_path):
data = np.load(data_path)
print('Loading training data from ' + data_path)
return data['image_data'], data['box_data']
image_data = []
box_data = []
with open(annotation_path) as f:
for line in f.readlines():
line = line.split(' ')
filename = line[0]
image = Image.open(filename)
boxed_image = letterbox_image(image, tuple(reversed(input_shape)))
image_data.append(np.array(boxed_image,dtype='uint8'))
boxes = np.zeros((max_boxes,5), dtype='int32')
for i, box in enumerate(line[1:]):
if i < max_boxes:
boxes[i] = np.array(list(map(int,box.split(','))))
else:
break
image_size = np.array(image.size)
input_size = np.array(input_shape[::-1])
new_size = (image_size * np.min(input_size/image_size)).astype('int32')
boxes[:i+1, 0:2] = (boxes[:i+1, 0:2]*new_size/image_size + (input_size-new_size)/2).astype('int32')
boxes[:i+1, 2:4] = (boxes[:i+1, 2:4]*new_size/image_size + (input_size-new_size)/2).astype('int32')
box_data.append(boxes)
image_data = np.array(image_data)
box_data = np.array(box_data)
np.savez(data_path, image_data=image_data, box_data=box_data)
print('Saving training data into ' + data_path)
return image_data, box_data
示例2: prepare_keras_data
# 需要导入模块: from yolo3 import utils [as 别名]
# 或者: from yolo3.utils import letterbox_image [as 别名]
def prepare_keras_data(self, image):
if self.model_image_size != (None, None):
assert self.model_image_size[0] % 32 == 0, 'Multiples of 32 required'
assert self.model_image_size[1] % 32 == 0, 'Multiples of 32 required'
boxed_image = letterbox_image(image, tuple(reversed(self.model_image_size)))
else:
new_image_size = (image.width - (image.width % 32),
image.height - (image.height % 32))
boxed_image = letterbox_image(image, new_image_size)
image_data = np.array(boxed_image, dtype='float32')
image_data /= 255.
image_data = np.expand_dims(image_data, 0) # Add batch dimension.
return image_data
示例3: parse_image
# 需要导入模块: from yolo3 import utils [as 别名]
# 或者: from yolo3.utils import letterbox_image [as 别名]
def parse_image(self, image):
decoded_image = tf.io.decode_image(image, channels=3, dtype=tf.float32)
decoded_image.set_shape([None, None, 3])
letterboxed_image = letterbox_image(decoded_image,
self.input_shapes)
return decoded_image, letterboxed_image
示例4: detect_image
# 需要导入模块: from yolo3 import utils [as 别名]
# 或者: from yolo3.utils import letterbox_image [as 别名]
def detect_image(self, image):
if self.is_fixed_size:
assert self.model_image_size[0]%32 == 0, 'Multiples of 32 required'
assert self.model_image_size[1]%32 == 0, 'Multiples of 32 required'
boxed_image = letterbox_image(image, tuple(reversed(self.model_image_size)))
else:
new_image_size = (image.width - (image.width % 32),
image.height - (image.height % 32))
boxed_image = letterbox_image(image, new_image_size)
image_data = np.array(boxed_image, dtype='float32')
#print(image_data.shape)
image_data /= 255.
image_data = np.expand_dims(image_data, 0) # Add batch dimension.
out_boxes, out_scores, out_classes = self.sess.run(
[self.boxes, self.scores, self.classes],
feed_dict={
self.yolo_model.input: image_data,
self.input_image_shape: [image.size[1], image.size[0]],
K.learning_phase(): 0
})
return_boxs = []
for i, c in reversed(list(enumerate(out_classes))):
predicted_class = self.class_names[c]
if predicted_class != 'person' :
continue
box = out_boxes[i]
# score = out_scores[i]
x = int(box[1])
y = int(box[0])
w = int(box[3]-box[1])
h = int(box[2]-box[0])
if x < 0 :
w = w + x
x = 0
if y < 0 :
h = h + y
y = 0
return_boxs.append([x,y,w,h])
return return_boxs
示例5: detect_image
# 需要导入模块: from yolo3 import utils [as 别名]
# 或者: from yolo3.utils import letterbox_image [as 别名]
def detect_image(self, image):
if self.is_fixed_size:
assert self.model_image_size[0]%32 == 0, 'Multiples of 32 required'
assert self.model_image_size[1]%32 == 0, 'Multiples of 32 required'
boxed_image = letterbox_image(image, tuple(reversed(self.model_image_size)))
else:
new_image_size = (image.width - (image.width % 32),
image.height - (image.height % 32))
boxed_image = letterbox_image(image, new_image_size)
image_data = np.array(boxed_image, dtype='float32')
#print(image_data.shape)
image_data /= 255.
image_data = np.expand_dims(image_data, 0) # Add batch dimension.
out_boxes, out_scores, out_classes = self.sess.run(
[self.boxes, self.scores, self.classes],
feed_dict={
self.yolo_model.input: image_data,
self.input_image_shape: [image.size[1], image.size[0]],
K.learning_phase(): 0
})
return_boxs = []
return_scores = []
for i, c in reversed(list(enumerate(out_classes))):
predicted_class = self.class_names[c]
if predicted_class != 'person' :
continue
box = out_boxes[i]
score = out_scores[i]
x = int(box[1])
y = int(box[0])
w = int(box[3]-box[1])
h = int(box[2]-box[0])
if x < 0 :
w = w + x
x = 0
if y < 0 :
h = h + y
y = 0
return_boxs.append([x,y,w,h])
return_scores.append(score)
return return_boxs, return_scores
示例6: detect_image
# 需要导入模块: from yolo3 import utils [as 别名]
# 或者: from yolo3.utils import letterbox_image [as 别名]
def detect_image(self, image):
if self.is_fixed_size:
assert self.model_image_size[0]%32 == 0, 'Multiples of 32 required'
assert self.model_image_size[1]%32 == 0, 'Multiples of 32 required'
boxed_image = letterbox_image(image, tuple(reversed(self.model_image_size)))
else:
new_image_size = (image.width - (image.width % 32),
image.height - (image.height % 32))
boxed_image = letterbox_image(image, new_image_size)
image_data = np.array(boxed_image, dtype='float32')
#print(image_data.shape)
image_data /= 255.
image_data = np.expand_dims(image_data, 0) # Add batch dimension.
out_boxes, out_scores, out_classes = self.sess.run(
[self.boxes, self.scores, self.classes],
feed_dict={
self.yolo_model.input: image_data,
self.input_image_shape: [image.size[1], image.size[0]],
K.learning_phase(): 0
})
return_boxs = []
for i, c in reversed(list(enumerate(out_classes))):
predicted_class = self.class_names[c]
list3 = ["motorbike","car", "bus","bicycle"]
for pp in list3:
if predicted_class != pp :
continue
box = out_boxes[i]
# score = out_scores[i]
x = int(box[1])
y = int(box[0])
w = int(box[3]-box[1])
h = int(box[2]-box[0])
if x < 0 :
w = w + x
x = 0
if y < 0 :
h = h + y
y = 0
return_boxs.append([x,y,w,h])
return return_boxs
开发者ID:Akhtar303,项目名称:Vehicle-Detection-and-Tracking-Usig-YOLO-and-Deep-Sort-with-Keras-and-Tensorflow,代码行数:48,代码来源:yolo.py