Merge branch 'refs/heads/local'
# Conflicts: # app/service/attribute/service_att_recognition.py # app/service/design/utils/design_ensemble.py # app/service/generate_image/utils/image_processing.py
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
import logging
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
import torch
|
||||||
import cv2
|
import cv2
|
||||||
import mmcv
|
import mmcv
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import torch
|
from minio import Minio
|
||||||
import tritonclient.http as httpclient
|
import tritonclient.http as httpclient
|
||||||
|
|
||||||
from app.core.config import *
|
from app.core.config import *
|
||||||
from app.schemas.attribute_retrieve import AttributeRecognitionModel
|
from app.schemas.attribute_retrieve import AttributeRecognitionModel
|
||||||
from app.service.utils.oss_client import oss_get_image
|
from app.service.utils.oss_client import oss_get_image
|
||||||
@@ -108,7 +108,7 @@ class AttributeRecognition:
|
|||||||
def preprocess(img):
|
def preprocess(img):
|
||||||
img = mmcv.imread(img)
|
img = mmcv.imread(img)
|
||||||
img_scale = (224, 224)
|
img_scale = (224, 224)
|
||||||
img = cv2.resize(img, img_scale, interpolation=cv2.INTER_LINEAR)
|
img = cv2.resize(img, img_scale)
|
||||||
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
||||||
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
||||||
return preprocessed_img
|
return preprocessed_img
|
||||||
|
|||||||
@@ -41,10 +41,7 @@ class CategoryRecognition:
|
|||||||
img = mmcv.imread(img)
|
img = mmcv.imread(img)
|
||||||
# ori_shape = img.shape[:2]
|
# ori_shape = img.shape[:2]
|
||||||
img_scale = (224, 224)
|
img_scale = (224, 224)
|
||||||
scale_factor = []
|
img = cv2.resize(img, img_scale)
|
||||||
img, x, y = mmcv.imresize(img, img_scale, return_scale=True)
|
|
||||||
scale_factor.append(x)
|
|
||||||
scale_factor.append(y)
|
|
||||||
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
||||||
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
||||||
return preprocessed_img
|
return preprocessed_img
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ def keypoint_preprocess(img_path):
|
|||||||
img = mmcv.imread(img_path)
|
img = mmcv.imread(img_path)
|
||||||
img_scale = (256, 256)
|
img_scale = (256, 256)
|
||||||
h, w = img.shape[:2]
|
h, w = img.shape[:2]
|
||||||
|
img = cv2.resize(img, img_scale)
|
||||||
w_scale = img_scale[0] / w
|
w_scale = img_scale[0] / w
|
||||||
h_scale = img_scale[1] / h
|
h_scale = img_scale[1] / h
|
||||||
img = cv2.resize(img, img_scale, interpolation=cv2.INTER_LINEAR)
|
|
||||||
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
||||||
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
||||||
return preprocessed_img, (w_scale, h_scale)
|
return preprocessed_img, (w_scale, h_scale)
|
||||||
@@ -84,7 +84,7 @@ def seg_preprocess(img_path):
|
|||||||
# 如果图片size任意一边 大于 1024, 则会resize 成1024
|
# 如果图片size任意一边 大于 1024, 则会resize 成1024
|
||||||
if ori_shape != (img_scale_w, img_scale_h):
|
if ori_shape != (img_scale_w, img_scale_h):
|
||||||
# mmcv.imresize(img, img_scale_h, img_scale_w) # 老代码 引以为戒!哈哈哈~ h和w写反了
|
# mmcv.imresize(img, img_scale_h, img_scale_w) # 老代码 引以为戒!哈哈哈~ h和w写反了
|
||||||
img = cv2.resize(img, (img_scale_h, img_scale_w), interpolation=cv2.INTER_LINEAR)
|
img = cv2.resize(img, (img_scale_h, img_scale_w))
|
||||||
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
||||||
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
||||||
return preprocessed_img, ori_shape
|
return preprocessed_img, ori_shape
|
||||||
|
|||||||
@@ -16,14 +16,8 @@ logger = logging.getLogger()
|
|||||||
def seg_preprocess(img_path):
|
def seg_preprocess(img_path):
|
||||||
img = mmcv.imread(img_path)
|
img = mmcv.imread(img_path)
|
||||||
ori_shape = img.shape[:2]
|
ori_shape = img.shape[:2]
|
||||||
img_scale_w, img_scale_h = ori_shape
|
img_scale = ori_shape
|
||||||
if ori_shape[0] > 1024:
|
img = cv2.resize(img, img_scale)
|
||||||
img_scale_w = 1024
|
|
||||||
if ori_shape[1] > 1024:
|
|
||||||
img_scale_h = 1024
|
|
||||||
# 如果图片size任意一边 大于 1024, 则会resize 成1024
|
|
||||||
if ori_shape != (img_scale_w, img_scale_h):
|
|
||||||
img = cv2.resize(img, (img_scale_h, img_scale_w), interpolation=cv2.INTER_LINEAR)
|
|
||||||
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
||||||
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
||||||
return preprocessed_img, ori_shape
|
return preprocessed_img, ori_shape
|
||||||
@@ -249,12 +243,8 @@ def stain_detection(image, user_id, category, tasks_id, spot_size=100):
|
|||||||
def generate_category_recognition(image, gender):
|
def generate_category_recognition(image, gender):
|
||||||
def preprocess(img):
|
def preprocess(img):
|
||||||
img = mmcv.imread(img)
|
img = mmcv.imread(img)
|
||||||
# ori_shape = img.shape[:2]
|
|
||||||
img_scale = (224, 224)
|
img_scale = (224, 224)
|
||||||
scale_factor = []
|
img = cv2.resize(img, img_scale)
|
||||||
img, x, y = mmcv.imresize(img, img_scale, return_scale=True)
|
|
||||||
scale_factor.append(x)
|
|
||||||
scale_factor.append(y)
|
|
||||||
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
||||||
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
||||||
return preprocessed_img
|
return preprocessed_img
|
||||||
|
|||||||
Reference in New Issue
Block a user