본문 바로가기

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_.. 더보기
현재 모델의 state_dict()가 갖는 key값만 저장된 state_dict()로 부터 불러오기 pretrained_dict = {k: v for k, v in checkpoint['scratch_state_dict'].items() if k in self.scratch.state_dict()} self.scratch.load_state_dict(pretrained_dict) 더보기
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()) 더보기
nuScenes 데이터셋의 이해 from nuscenes.nuscenes import NuScenes nusc = NuScenes(version='v1.0-trainval', dataroot=dataroot, verbose=True) 1. Scene nuScenes는 20초 가량 길이의 scene이 1000개가 존재. 이 중 850개만을 공개. # load first scene my_scene = nusc.scene[0] 2. Sample scene에는 여러개의 sample이 존재. 하나의 sample이 특정 시각에 수집된 각종 데이터 (camera, lidar, radar 등)를 의미. nuScene은 annotation을 2Hz로 했으므로, 두 sample 사이의 시간차는 약 0.5초 이며 하나의 scene에는 약 40개의 samp.. 더보기
[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.. 더보기
Fast JPEG image loading by TurboJPEG from turbojpeg import TurboJPEG # define class class TurboJpegLoader(): def __init__(self, suffix, resize=None, crop=None): super(TurboJpegLoader, self).__init__() self.suffix = suffix self.resize = resize self.crop = crop self.jpeg = TurboJPEG() def __call__(self, path): if (path.exists() is not True): sys.exit(f'[Error] {str(path)} does not exists!!') in_file = open(str(path), 'rb') bgr_array .. 더보기
Pathlib 사용 예제 from PIL import Image import matplotlib.pyplot as plt from pathlib import Path def resize_and_crop_image(img, resize_dims, crop): img = img.resize(resize_dims, resample=Image.BILINEAR) img = img.crop(crop) return img # current working directory cwd = Path.cwd() # add path cfg_path = cwd.parent / 'config/CVTpro/data.json' cfg = read_json(path=str(cfg_path)) # Image resize and crop ori_dims = (cfg.. 더보기