본문 바로가기

Python

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.. 더보기
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) 더보기
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() 더보기
[Anaconda] Conda env clone 1) Export existing env conda env export > pytorch.yml 2) clone the exported env conda env create -f pytorch.yml 더보기
numpy array with increasing integer element b = np.arange(1, 10) 더보기
generate a sequence of random int in range import random nums = [x for x in range(10)] random.shuffle(nums) print(nums) 더보기