(tensor == target_value).nonzero(as_tuple=True) python list에서 특정 값의 index를 찾는 것 처럼 tensor에서 특정 값의 index 위치 정보를 얻고 싶으면 상단 command를 활용하면 된다. 아래는 이를 활용한 예제 new_sizes = tensor([4, 4, 0, 4, 4, 4, 3, 4, 4, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0, 4, 4, 4, 3, 4, 4, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0, 4, 4, 5, 0, 4, 4, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0, 4, 4, 4, 3, 4, 4, 4, 3, 4, 4, 6, 3, 4, 4, 5, 3, 4, 4, 4, 0, ..
사소한 Tip . 오류 해결법
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbRearW%2FbtrScRjYyS4%2Fha0xHqJ45JbqP7gQPqMQK0%2Fimg.png)
pytorch로 구성된 모델을 로딩하는 도중, 아무런 반응이 없이 멈춰있는 경우가 발생했다. 실제 Ctrl C로 로그를 살펴보니 아래처럼 cpp_extension.py에서 time.sleep으로 멈춘 경우가 발생했다. File "/opt/conda/envs/PROJECT/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1080, in load return _jit_compile( File "/opt/conda/envs/PROJECT/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1307, in _jit_compile baton.wait() File "/opt/conda/e..
pdf2image라는 패키지를 사용해서 PDF 내 각 페이지를 이미지로 저장해보자. 아래 커맨드로 pdf2image를 설치해준다. pip install pdf2image 아래는 내가 짠 샘플 코드로, 각 pdf 별 세부 하위폴더를 만든 후 페이지 별 이미지를 저장하게끔 하였다. 코드는 단순하고, 주석도 넣어놨기 때문에 부가적인 설명은 제외한다. 추가적으로 glob, tqdm 정도만 pip로 설치해줘도 될 것 같다. import os import glob from pdf2image import convert_from_path from tqdm import tqdm if __name__ == "__main__": # target_path : pdf 문서가 있는 경로 target_path = "./pdf_da..
다음과 같이 짝수개 요소가 들어있는 list를 보고, 두개씩 짝지어서 return하고 싶을 때 간단한 기록용 #for문을 쓰면 직관적이지만, 깔끔하지 못함 test = [1, 2, 3, 4, 5, 6, 7, 8] new = [] for i in range(0, len(test), 2): new.append([test[i], test[i+1]]) print(new) #[[1, 2], [3, 4], [5, 6], [7, 8]] 한줄로 묶기위해선 zip과 list slicing을 활용 # 한 줄로 작성 test = [1,2,3,4,5,6,7,8] result = [[x, y] for x, y in zip(test[0::2], test[1::2])] print(result) # [[1, 2], [3, 4], [..
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FSw4Hn%2FbtrQpTXOhAZ%2FFmop3u3UXMetf2K5uoIZw1%2Fimg.png)
json 으로 열고 작성할 때, 아래 사진과 같이 unicode형태로 한글이 저장되는 현상이 존재한다. with open(output_jsonpath, 'w', encoding='utf-8-sig') as f: output_json = json.dumps(output_json_dict, ensure_ascii=False, indent='\t') f.write(output_json) 다음과 같이 "ensure_ascii=False"를 dumps 함수 인자로 넣어주면 해당 현상이 사라진다.
pip로 Package 설치 또는 삭제 과정에서 다음과 같은 에러를 뱉는 경우가 존재한다. 이럴 때는 아래와 같이 "--ignore-installed" 옵션을 두어서 설치하면 정상적인 설치가 가능하다. pip install --ignore-installed PACKAGE_NAME # 만약 requirements.txt로 한번에 여러 패키지를 설치할때도 동일하게 처리해 주면 된다. pip install --ignore-installed -r requirements.txt
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fd6i2Zg%2FbtrPQNEK9Y0%2FDrlu1TLae0rv4zBRW1zfm0%2Fimg.png)
아래 링크 참고: https://stackoverflow.com/questions/4716533/how-to-attach-debugger-to-a-python-subproccess How to attach debugger to a python subproccess? I need to debug a child process spawned by multiprocessing.Process(). The pdb degugger seems to be unaware of forking and unable to attach to already running processes. Are there any smarter python stackoverflow.com import sys import pdb class Forke..
rsync --help로 옵션을 확인하고 진행 특정 파일을 제외하고 싶을 때 rsync -av --exclude '$FILE_NAME' $SRC_DIRECTORY $DST_DIRECTORY ex) rsync -a --exclude '*.txt' ./ ../target_folder 특정 디렉토리(폴더)를 제외하고 싶을 때 rsync -av --exclude '$FOLDER_NAME' $SRC_DIRECTORY $DST_DIRECTORY ex) rsync -av --exclude 'data' ./ ../target_folder +) 여러 폴더, 디렉토리, 파일을 제외하고 싶을 때 rsync -av --exclude {'$FOLDER_NAME','$FOLDER_NAME_2','$FILE_NAME','$FOLD..
https://research.google/pubs/ Publications – Google Research Google publishes hundreds of research papers each year. Publishing our work enables us to collaborate and share ideas with, as well as learn from, the broader scientific community. research.google
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbcnDPs%2FbtrMKmb9mds%2Fi0lcfp1RINk9EDRk5FFTiK%2Fimg.png)
vscode를 처음 설치하면 기본 설정으로 파일을 열때마다, 해당 파일이 있는 프로젝트의 폴더가 자동으로 펼쳐진다. 즉, 내가 원하는 폴더를 보고 싶은데 탭 전환할때마다 거슬리게 왔다갔다 한다. 아래의 Auto Reveal 설정을 꺼버리자. 좌측 하단 톱니바퀴 > 설정 > 창 > 탐색기 > Auto Reveal을 True에서 False로 변경
mmdetection 설치 후, 아래 cmd 실행 중 발생한 오류 mim download mmdet --config yolov3_mobilenetv2_320_300e_coco --dest . mmengine이라는 package를 깔아달라고 한다. File "/opt/conda/envs/openmmlab/lib/python3.8/site-packages/mim/commands/download.py", line 93, in download raise ImportError(highlighted_error(msg)) ImportError: Please install mmengine to use the download command. mim install mmengine 이거로 깔고 재실행하니 잘 된다
mmdetection 실행 중, 발생한 오류로 설치된 PIL(Pillow)의 버전이 너무 높아 호환이 안될 때 발생하는 에러라고 한다. File "/opt/conda/envs/openmmlab/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 5, in from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/opt/conda/envs/openmmlab/lib/python3.8/site-packages/PIL/__init__.py) pip list 등으로 현재 설치..
TypeError: cannot perform reduce with flexible type 주로, python list 내 숫자값을 연산하는 과정에서 생기는 오류로 내부에 숫자형이 아닌 다른 값(ex. string type)이 들어가 있으면 나오는 에러다. 내 경우엔 아래처럼 np.min()연산을 사용하는 과정 중에 발생했고, 실제로 해당 값을 출력해보니 숫자값이 아닌 문자형 데이터가 들어가 있는 것을 확인하였다 np.min(a[0::2]) print(a[0::2])#['108', '42', '211', '42', '211', '62', '108', '62'] list의 내부 값이 다 "" 따옴표로 묶여있는 string값인데, 미처 앞에서 int형으로 바꿔주지 않았던 것 같다. 아래와 같은 두 가지 방..
pip install 명령어 pip install ipython conda install 명령어 conda install -c anaconda ipython 상단 중 원하는 거로 ipython을 설치하면 문제는 해결된다.
1. itertools.islice() python에서 Dictionary는 key-value로 이루어진 포맷이기 때문에, 애초에 list처럼 0~2번 요소까지 slicing 이런 개념이 없다. 하지만 python3부터 itertools.islice함수를 사용하면 해당 dictionary의 items 함수를 활용하여 슬라이싱 할 수 있다. import itertools d = {1: 2, 3: 4, 5: 6} dict(itertools.islice(d.items(), 2)) --- {1: 2, 3: 4} 2. dict to list, list to dict 그 외의 방법으로는 아래와 같이 list로 변경하고, 이를 다시 dictionary로 변경하는 2번째 방법이 있다. d = {1:2, 3:4, 5:6..