일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- mysql
- 핑거스타일
- paramiko
- pandas
- 프로그래머스
- JSON
- SSH
- Visual Studio
- windows forms
- ubuntu
- error
- VS Code
- Python
- pytorch
- label
- LIST
- OpenCV
- 오류
- Docker
- C
- YOLO
- Selenium
- Linux
- 채보
- Numpy
- 기타 연주
- C#
- C++
- pip
- 컨테이너
- Today
- Total
목록Python (115)
기계는 거짓말하지 않는다
from PIL import Image import cv2 img = cv2.imread("img.png") # 299 x 507 h, w, c = img.shape # height, width, channel print(h, w, c) img = Image.open("img.png") w, h = img.size # wdith, height print(w, h)
import torch model = # 모델 생성 # 모델 저장 save_name = "model_final" torch.save(model.state_dict(), f"Directory/{save_name}.pth") # 모델 불러오기 load_name = "model_final" model.load_state_dict(torch.load(f"Directory/{load_name}.pth")) # 경로, 저장 모델 이름 # 설정 값 세부 저장 checkpoint = { 'model': model.state_dict(), 'optimizer': optimizer.state_dict(), 'lr_scheduler': lr_scheduler.state_dict(), 'epoch': epoch } torch..
Python에서 파일 open시 볼 수 있는 에러이다. 실제로 파일 권한이 없어서 열 수 없는 경우 파일 권한을 변경하면 된다. 권한이 있는데도 발생한다면 Windows에서 거의 대부분 file이 아닌 directory를 open하고 있을 수 있다. path를 확인하고 directory를 열고 있지 않은지 검사한다.
리스트 내포를 이용하거나 [value] * n으로 표현하면 된다. # 길이 100 list를 생성하고 0으로 초기화 temp_list = [0 for i in range(100)] temp_list = [0] * 100 # [value] * n
Numpy 배열을 transpose를 이용하여 축을 바꿀 수 있다. transpose 함수의 매개변수는 축의 번호이고 축의 개수만큼 입력해야 한다. (3차원 -> 3개) 축의 인덱스는 0부터 시작한다. 예를 들어 행, 열의 2차원 배열이 있다면 transpose(1, 0) (열, 행)으로 행, 열을 바꿀 수 있다. 이때, 첫 번째 매개변수는 행, 두 번째는 열이 되며 행 매개변수에 열(1)로 바꾸고 열 매개변수에 행(0)으로 바꾼다. shape가 (3, 2, 4) (높이, 행, 열)인 3차원 배열이 있을 때, transpose(1, 2, 0)을 하게 되면 index 0 = 높이, 1 = 행, 2 = 열이 되고 (3(높이), 2, 4)의 높이 자리에 행(index=1, shape=2) (3, 2(행), 4..
클래스에 여러 인스턴스 변수의 기준에 따라 정렬할 때 비교함수 구현 # lt(a, b): a = b operator.ge(a, b) operator.__ge__(a, b) # boolean 값으로 해석할 수도 있고, # 그렇지 않은 임의의 값을 반환할 수도 있음 class TempClass: def __init__(self, string:str, index:int): if type(string) is not str: raise Exception("not string") if type(index) is no..
TypeError: 'int' object is not subscriptable 인덱스로 지정할 수 없는 경우(단일 값) # TypeError: 'int' object is not subscriptable intValue = 10 print(intValue[3]) intArray = [1, 2, 3] print(intArray[0][1]) TypeError: list indices must be integers or slices, not str TypeError: string indices must be integers 숫자 형식 인덱스에 Key 형식으로 받은 경우 # TypeError: list indices must be integers or slices, not str intArray = [1, 2..
Python 형 변환 시 다음과 같은 오류를 볼 때가 있다. ValueError: invalid literal for int() with base 10 아래 코드는 오류를 일으킨다. str = "35.231" intVal = int(str) print(intVal) string을 int로 형 변환 시 소수점 형식일 경우 우선 float 변환 후 진행한다. str = "35.231" intVal = int(float(str)) print(intVal)