Python 썸네일형 리스트형 Scatter plot with subfigures with open('attn_result.pickle', 'rb') as fr: attn_result = pickle.load(fr) ref_cam = 'cam0' # tgt_cam_num = 3 image_ref = attn_result['cam0']['image'] # image_tgt = attn_result['cam'+str(tgt_cam_num)]['image'] Hh, Wh = image_ref.shape[:2] # Hl Wl nhead ncam npts 2 position = attn_result['cam0']['sample_position'] weight = attn_result['cam0']['attention_weight'] Hl, Wl = position.shape[:2] scale_.. 더보기 If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. Solution: pip install protobuf==3.20.* 더보기 Pytorch how to use nn.ModuleDict with zip for iteration class TEST(nn.Module): def __init__(self): super().__init__() self.conv = nn.Conv2d(10, 10, 1) def forward(self, x): return self.conv(x) num_res = 2 BEVEncoder = nn.ModuleDict() UpSampler = nn.ModuleDict() for _ in range(num_res): IsSelfAttn = True if _ == 0 else False BEVEncoder[str(_)] = TEST() if (_ == 0): UpSampler[str(_)] = None else: UpSampler[str(_)] = TEST() for (_, enc), (_, up) in sort.. 더보기 Image Augmentation (Photometric) 방법 class PhotoMetricDistortion: """Apply photometric distortion to image sequentially, every transformation is applied with a probability of 0.5. The position of random contrast is in second or second to last. 1. random brightness 2. random contrast (mode 0) 3. convert color from BGR to HSV 4. random saturation 5. random hue 6. convert color from HSV to BGR 7. random contrast (mode 1) 8. randomly s.. 더보기 PIL.image 라이브러리 사용법 1. Image Open from PIL import Image img = Image.open('./test.png') 2. Image Show img.show() 3. Image Characteristic img.filename # './test.png' img.formate # 'JPEG' img.size # (400, 400) img.mode # 'RGB' img.width # 400 img.height # 400 4. 이미지 크기 변경 resize_img = img.resize((WIDTH, HEIGHT), Image.NEAREST) resize_img = img.resize((WIDTH, HEIGHT), Image.BILINEAR) resize_img = img.resize((WIDTH, HEI.. 더보기 Change working directory to current location abspath = os.path.dirname(os.path.realpath(__file__)) os.chdir(Path(abspath).absolute()) 더보기 Draw HSV color wheel # color pallet grid_2D = grid_3D[0, :2].view(2, -1) # 2 (h w) radius = grid_2D.pow(2).sum(0).unsqueeze(0) # 1 (h w) radius = radius / radius.max() radian = torch.atan2(grid_2D[1], grid_2D[0]) chk_m = radian < 0 radian[chk_m] += 2 * np.pi # from (-pi, pi) to (0, 2pi) h = (radian-radian.min()) / (radian.max()-radian.min()) # normalized from 0-1 s = radius # saturation is set as a function of radia.. 더보기 [matplotlib] Creating multiple figures in one plot # Vertical fig, axs = plt.subplots(2) fig.suptitle('Vertically stacked subplots') axs[0].plot(x, y) axs[1].plot(x, -y) # Horizontal fig, (ax1, ax2) = plt.subplots(2) fig.suptitle('Vertically stacked subplots') ax1.plot(x, y) ax2.plot(x, -y) 더보기 ImportError: cannot import name '_NewEmptyTensorOp' from 'torchvision.ops.misc' 해당 에러는 torchvision의 version 확인을 제대로 못해서 발생하는 문제이다. import torch import torch.nn as nn import torch.distributed as dist from torch import Tensor # needed due to empty tensor bug in pytorch and torchvision 0.5 import torchvision if float(torchvision.__version__[:3]) < 0.5: import math from torchvision.ops.misc import _NewEmptyTensorOp def _check_size_scale_factor(dim, size, scale_factor): # type: .. 더보기 Resize and crop images in a specific directory from tqdm import tqdm import logging import traceback import argparse from PIL import Image import matplotlib.pyplot as plt import cv2 import random from pathlib import Path from utils.functions import read_config, read_json from IPython.display import display def resize_and_crop_image(img, resize_dims, crop): img = img.resize(resize_dims, resample=Image.BILINEAR) img = img.crop(crop) return img.. 더보기 이전 1 2 3 4 다음