본문 바로가기

Python

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.. 더보기
Python에서 Warning 문구 제거하기 아래의 명령어를 코드의 맨 윗줄에 추가해준다. import warnings warnings.filterwarnings("ignore") 더보기
Pandas 명령어 모음 1. Column의 Key 값 Return keys = df.columns.to_list() for key in keys: df.colums[key] 2. 데이터를 Numpy Arrary로 변환 df_train.values df_train.to_numpy() 3. 특정 keys 값들의 데이터 프레임 생성 df[['x', 'y']] 4. 특정 key 값의 데이터 중 Unique한 데이터 추출 df['trackId'].unique() 5. 특정 조건을 만족하는 row 데이터 추출 df_train[df_train['frame']==fidx] 6. 중복되는 column 값을 갖는 row 제거하기 # frame, trackId 값이 같은 row가 모두 제거됨. 첫 번째 데이터를 남기고. df_scene.drop_.. 더보기
python에서 evaluate과 tqdm 같이 사용하기 for _, scene in enumerate(tqdm(dataset[0], desc='refactoring train data')): self.train_data += self.refactoring(scene) 더보기
nuScenes devkit 명령어 모음 (useful commands) 1. How to get scene records for scene_record in self.nusc.scene: yield scene_record['name'], scene_record 2. How to get sample records from scene record sample_token = scene_record['first_sample_token'] while sample_token: sample_record = self.nusc.get('sample', sample_token) sample_token = sample_record['next'] 3. How to get egolidar pose from sample record lidar_record = self.nusc.get('sample_.. 더보기
For문을 이용한 Dictionary의 key, item 접근 # method 1 for key, value in batch.items(): if (exp_dim): batch[key] = batch[key].unsqueeze(0).cuda() else: batch[key] = batch[key].cuda() # method 2 for _, (key, value) in enumerate(batch.items()): if (exp_dim): batch[key] = batch[key].unsqueeze(0).cuda() else: batch[key] = batch[key].cuda() 더보기
Gaussian, LogGaussian PDF in Pytorch def GaussianPDF(mean, logvar, z): r""" Return the PDF value of z in N(mean,exp(logvar)) mean, logvar : [*, dim_z] z : [*, N, dim_z] return: [*, N, dim_z] """ if type(mean) is torch.Tensor: mean, logvar = mean.unsqueeze(-2), logvar.unsqueeze(-2) return 1/(np.sqrt(2*np.pi)*torch.exp(logvar*0.5)) * torch.exp(-((z-mean)**2) / (2*torch.exp(logvar))) elif type(mean) is np.ndarray: mean, logvar = np.ex.. 더보기
how to plot a histogram : matplotlib import matplotlib.pyplot as plt# the histogram of the data bins = [] for i in range(-1000, 1001): bins.append(i) values, bins, patches = plt.hist(np.squeeze(np.array(steers)), np.squeeze(np.array(bins)), normed=False) plt.xlabel('Steering Angle (x1000.0)') plt.ylabel('Occurrence') plt.grid(True) plt.axis([-500, 500, 0, 1000]) plt.show() # for CDF plot cdf = [] acc_value = 0 for i in range(0, len.. 더보기
how to read/save an image as bmp in python cv2.imread(parse_file_name_read(read_dir, countFrames))cv2.imwrite(parse_file_name_save(save_dir, countFrames), image) 더보기