當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.letterbox_image方法代碼示例

本文整理匯總了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 
開發者ID:scutan90,項目名稱:YOLO-3D-Box,代碼行數:38,代碼來源:train.py

示例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 
開發者ID:onnx,項目名稱:keras-onnx,代碼行數:15,代碼來源:yolov3.py

示例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 
開發者ID:fsx950223,項目名稱:mobilenetv2-yolov3,代碼行數:8,代碼來源:yolo.py

示例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 
開發者ID:jguoaj,項目名稱:multi-object-tracking,代碼行數:44,代碼來源:yolo.py

示例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 
開發者ID:Qidian213,項目名稱:deep_sort_yolov3,代碼行數:46,代碼來源:yolo.py

示例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


注:本文中的yolo3.utils.letterbox_image方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。