You've already forked DataMate
init datamate
This commit is contained in:
6
runtime/ops/formatter/img_formatter/__init__.py
Normal file
6
runtime/ops/formatter/img_formatter/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datamate.core.base_op import OPERATORS
|
||||
|
||||
OPERATORS.register_module(module_name='ImgFormatter',
|
||||
module_path="ops.formatter.img_formatter.process")
|
||||
16
runtime/ops/formatter/img_formatter/metadata.yml
Normal file
16
runtime/ops/formatter/img_formatter/metadata.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
name: '读取图片文件'
|
||||
name_en: 'Image File Reader'
|
||||
description: '读取图片文件。'
|
||||
description_en: 'Reads image files.'
|
||||
language: 'Python'
|
||||
vendor: 'Huawei'
|
||||
raw_id: 'ImgFormatter'
|
||||
version: '1.0.0'
|
||||
types:
|
||||
- 'collect'
|
||||
modal: 'image'
|
||||
effect:
|
||||
before: ''
|
||||
after: ''
|
||||
inputs: 'image'
|
||||
outputs: 'image'
|
||||
35
runtime/ops/formatter/img_formatter/process.py
Normal file
35
runtime/ops/formatter/img_formatter/process.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# # -- encoding: utf-8 --
|
||||
|
||||
#
|
||||
# Description:
|
||||
# Create: 2024/1/30 15:24
|
||||
# """
|
||||
import time
|
||||
from typing import Dict, Any
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
from loguru import logger
|
||||
|
||||
from datamate.common.utils import numpy_to_bytes
|
||||
from datamate.core.base_op import Mapper
|
||||
|
||||
|
||||
class ImgFormatter(Mapper):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def execute(self, sample: Dict[str, Any]) -> Dict[str, Any]:
|
||||
start = time.time()
|
||||
file_name = sample[self.filename_key]
|
||||
file_type = "." + sample[self.filetype_key]
|
||||
file_path = sample[self.filepath_key]
|
||||
img_data = _img_extract(file_path)
|
||||
sample[self.data_key] = numpy_to_bytes(img_data, file_type)
|
||||
logger.info(f"fileName: {file_name}, method: ImgExtract costs {(time.time() - start):6f} s")
|
||||
return sample
|
||||
|
||||
|
||||
def _img_extract(file_path):
|
||||
return cv2.imdecode(np.fromfile(file_path, dtype=np.uint8), -1)
|
||||
Reference in New Issue
Block a user