Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

控制台会自动输出小数 #69

Open
ls-ash opened this issue May 4, 2023 · 5 comments
Open

控制台会自动输出小数 #69

ls-ash opened this issue May 4, 2023 · 5 comments

Comments

@ls-ash
Copy link

ls-ash commented May 4, 2023

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

@DefTruth
Copy link
Owner

DefTruth commented May 5, 2023

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

@ls-ash
Copy link
Author

ls-ash commented May 8, 2023

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

@DefTruth
Copy link
Owner

DefTruth commented May 8, 2023

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

@ls-ash
Copy link
Author

ls-ash commented May 8, 2023

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)

@DefTruth
Copy link
Owner

DefTruth commented May 9, 2023

最新的是0.1.6.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants