torchlm icon indicating copy to clipboard operation
torchlm copied to clipboard

控制台会自动输出小数

Open ls-ash opened this issue 2 years ago • 5 comments

是class LandmarksRandomScale(LandmarksTransform):里面,print(resize_scale_x) print(resize_scale_y),是更新时候没去掉吗?

ls-ash avatar May 04 '23 17:05 ls-ash

安装最新版本试试,最新的代码不会有这个log

DefTruth avatar May 05 '23 07:05 DefTruth

version = '0.1.6',这就是最新的吧

ls-ash avatar May 08 '23 02:05 ls-ash

可以提供下您的测试代码吗?

DefTruth avatar May 08 '23 08:05 DefTruth

import cv2 import numpy as np import torchvision import albumentations from torch import Tensor from typing import Tuple

import torchlm

def callable_array_noop( img: np.ndarray, landmarks: np.ndarray ) -> Tuple[np.ndarray, np.ndarray]: # Do some transform here ... return img.astype(np.uint32), landmarks.astype(np.float32)

def callable_tensor_noop( img: Tensor, landmarks: Tensor ) -> Tuple[Tensor, Tensor]: # Do some transform here ... return img, landmarks

if name == 'main': print(f"torchlm version: {torchlm.version}") seed = np.random.randint(0, 1000) np.random.seed(seed)

img_path = "D12E-D13E_DSC04509_a_1_D13E_a_1.png"

save_path = f"./output/agu/2_wflw_{seed}.jpg"
img = cv2.imread(img_path)[:, :, ::-1].copy()  # RGB


landmarks = [1,2]
landmarks = np.array(landmarks).reshape(1, 2)  # (5,2) or (98, 2) for WFLW

# some global setting will show you useful details
#torchlm.set_transforms_debug(True)
#torchlm.set_transforms_logging(True)
#torchlm.set_autodtype_logging(True)

transform = torchlm.LandmarksCompose([
    # use native torchlm transforms
    torchlm.LandmarksRandomScale(prob=0.5),
    torchlm.LandmarksRandomTranslate(prob=0.5),
    torchlm.LandmarksRandomShear(prob=0.5),
    torchlm.LandmarksRandomMask(prob=0.5),
    torchlm.LandmarksRandomBlur(kernel_range=(5, 25), prob=0.5),
    torchlm.LandmarksRandomBrightness(prob=0.),
    torchlm.LandmarksRandomRotate(40, prob=0.5, bins=8),
    torchlm.LandmarksRandomCenterCrop((0.5, 1.0), (0.5, 1.0), prob=0.5),
    # bind torchvision image only transforms with a given bind prob
    torchlm.bind(torchvision.transforms.GaussianBlur(kernel_size=(5, 25)), prob=0.5),
    torchlm.bind(torchvision.transforms.RandomAutocontrast(p=0.5)),
    torchlm.bind(torchvision.transforms.RandomAdjustSharpness(sharpness_factor=3, p=0.5)),
    # bind albumentations image only transforms
    torchlm.bind(albumentations.ColorJitter(p=0.5)),
    torchlm.bind(albumentations.GlassBlur(p=0.5)),
    torchlm.bind(albumentations.RandomShadow(p=0.5)),
    # bind albumentations dual transforms
    torchlm.bind(albumentations.RandomCrop(height=200, width=200, p=0.5)),
    torchlm.bind(albumentations.RandomScale(p=0.5)),
    torchlm.bind(albumentations.Rotate(p=0.5)),
    # bind custom callable array functions with a given bind prob
    torchlm.bind(callable_array_noop, bind_type=torchlm.BindEnum.Callable_Array, prob=0.5),
    # bind custom callable Tensor functions
    torchlm.bind(callable_tensor_noop, bind_type=torchlm.BindEnum.Callable_Tensor, prob=0.5),
    #torchlm.LandmarksResize((256, 256)),
    torchlm.LandmarksNormalize(),
    torchlm.LandmarksToTensor(),
    #torchlm.LandmarksToNumpy(),
    torchlm.LandmarksUnNormalize()
])

trans_img, trans_landmarks = transform(img, landmarks)

imgshow = trans_img.permute(1, 2, 0).numpy()
print('imgshow',imgshow,np.shape(imgshow))
cv2.imshow("picture", imgshow)
cv2.waitKey(0)

new_img = torchlm.draw_landmarks(imgshow, trans_landmarks, circle=2)
#new_img = torchlm.draw_landmarks(trans_img, trans_landmarks, circle=2)
print('new_img ',new_img,np.shape(new_img))
print(imgshow==new_img)
cv2.imwrite(save_path, new_img[:, :, ::-1])

# unset the global status when you are in training process
torchlm.set_transforms_debug(False)
torchlm.set_transforms_logging(False)
torchlm.set_autodtype_logging(False)

ls-ash avatar May 08 '23 12:05 ls-ash

最新的是0.1.6.10

DefTruth avatar May 09 '23 00:05 DefTruth