본문 바로가기

Python

Install a conda environment compatible with 'Resnoise' 0. install miniconda1. create conda env$ conda create -y -n resnoise python=3.82. activate created env$ source activate cvt3. install pytorch lightening through pip$ pip install pytorch-lightening==1.9.0 4. Reinstall pytorch, torchvision, cuda toolkit$ pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 --extra-index-url https://download.pytorch.org/whl/cu113 https://download.pytorch.org/w.. 더보기
3D points data scatter plot import pickle# Load tensor from the filewith open('tensor.pkl', 'rb') as f: loaded_tensor = pickle.load(f)grids = loaded_tensor[0] # num_cams x num_depth x H x W x 3grids = grids.view(-1, 3).to('cpu').numpy()import plotly.graph_objects as go# Sample data: sequence of 3D points (x, y, z)x_points = list(grids[:, 0])y_points = list(grids[:, 1])z_points = list(grids[:, 2])# Create a 3D scatter pl.. 더보기
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.. 더보기