일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
- 딥러닝
- WOX
- Linear algebra
- 수치해석
- Numerical Analysis
- 논문작성
- Julia
- 인공지능
- 생산성
- pytorch
- 에러기록
- 텝스공부
- Python
- 수식삽입
- teps
- MATLAB
- JAX
- 논문작성법
- matplotlib
- 옵시디언
- Statics
- 텝스
- 고체역학
- ChatGPT
- 우분투
- obsidian
- LaTeX
- Dear abby
- Zotero
- IEEE
- Today
- Total
목록프로그래밍 Programming (93)
뛰는 놈 위에 나는 공대생
MATLAB의 default colormap은 다음 구성으로 되어있다. 일반적인 그림에서는 문제가 되지 않을지라도 일반적으로 논문에서는 좀 더 눈에 띄는 색상들로 구분해주는 게 좋다고 한다. 그래서 classic plot을 보면 (matplotlib 참고) 왼쪽과 같이 채도가 높은 파란색, 빨간색 등을 사용한다. 그래서 MATLAB 코드를 사용해서 default colormap을 채도가 높은 파랑-빨강-초록-마젠타-시안-채도 낮은 노랑으로 분배하기 위한 코드를 작성하였다. newcolors = {'b','r','g','m','c','#bcbd22'} ; % blue, red, green, magenta, cyan, yellow with low saturation colororder(newcolors) 여..
나는 MATLAB에서 필요한 디폴트 설정을 한 함수에 넣어두고 코드에서 함수를 호출함으로써 쓰고 있었다. 그런데 이렇게 하면 항상 코드에 있는 경로에 디폴트 설정을 해놓은 함수를 넣어놔야하기 때문에 번거로움이 있다. 이러한 함수를 한 폴더에 저장해놓고, 매번 그 함수가 있는 경로를 추가할 수도 있을 것이다. 그 대신에, 내가 원하는 경로에 startup.m이라는 함수를 만들고 그 안에 코드를 작성해놓으면 MATLAB에서 시작할 때 그 함수 안에 있는 내용을 실행한다. 그래서 만약에 자신이 항상 쓰는 함수들을 모아놓은 폴더가 있으면 startup.m 코드 안에 addpath (경로) 를 넣어놓으면 시작할 때부터 바로 그 경로를 추가하기 때문에 언제든지 그 경로에 있는 함수들에 접근할 수 있다. 이 star..
Matplotlib은 figure를 도출하기 위해 중요한 라이브러리이다. 이 figure를 파일로 저장하기 위해서는 savefig라는 함수를 쓰는데 이 함수에서 설정할 수 있는 것들에 대해 이야기하려고 한다. 1. savefig의 argument savefig(fname, *, dpi='figure', format=None, metadata=None, bbox_inches=None, pad_inches=0.1, facecolor='auto', edgecolor='auto', backend=None, **kwargs ) 위의 savefig argument에서 fname은 저장할 파일이름이다. 여기에서 확장자를 지정하지 않으면 default로 png 파일로 저장한다. format에서도 확장자를 지정할 수 있..
필자는 컴퓨터 전공이 아니라서 아주 기초적인 컴공 지식 밖에 모른다. 그래서 다른 사람의 소스코드를 쓰다가 어려움을 겪었는데 간단한 결과를 소개하고자 한다. 내가 쓰려고 했던 것은 딥러닝 학습에서 네크워크의 gradient surface를 보여줄 수 있는 그림이었다. 이를 위해서 https://github.com/tomgoldstein/loss-landscape GitHub - tomgoldstein/loss-landscape: Code for visualizing the loss landscape of neural nets Code for visualizing the loss landscape of neural nets - GitHub - tomgoldstein/loss-landscape: Code f..
딥러닝 후에 visualization할 때 일일이 세팅을 정해줘야해서 번거롭다. 그래서 default setting을 위한 코드들을 미리 작성하고 필요할 때마다 복사해서 사용하고자 한다. 좋은 코드를 발견하면 계속 추가할 예정이다. 1. Grid setting import matplotlib as mpl # grid setting mpl.rcParams['grid.color'] = '#808080' mpl.rcParams['grid.linestyle'] = '--' mpl.rcParams['grid.linewidth'] = 0.5 mpl.rcParams.update({"axes.grid" : True}) 위의 세 줄은 색상, line style, linewidth에 대한 설정이다. 색상은 v.2.0에 적..
코드 상에서 특정 변수를 따로 gradient descent 방법으로 업데이트해야할 일이 있는데 이상하게 에러가 났다. 그래서 쉬운 예제를 통해서 이해를 해보고자 했다. a = torch.linspace(0., 2. * math.pi, steps=25, requires_grad=True) b = torch.sin(a) c = 2 * b d = c + 1 out = d.sum() out.backward(retain_graph=True) gradient = a.grad.clone().detach() a -= 0.001 * gradient print(a.requires_grad) 이렇게 코드를 짜면 RuntimeError: a leaf Variable that requires grad is being used..
PyTorch에서 dataloader 기능 중에 shuffle을 사용하고자했는데 다음과 같은 에러를 봤다. RuntimeError: Expected a 'cuda' device type for generator but found 'cpu' 참고로 나는 내가 만든 custom dataset을 class로 만들고, 그 클래스에 대하여 DataLoader를 만들었다. 인터넷을 검색하여 찾아보니 이 shuffle 기능을 위해 사용하는 generator가 cpu로 설정되어 있으면 그 device에서 generator를 생성하는 것으로 보였다. 나는 custom dataset에서 모두 데이터의 device를 cuda로 설정하는 작업을 거치기 때문에 오류가 생긴 것이다. 이 글에서 보면 generator를 설정할 수..
Tensorflow와 달리 PyTorch는 사용하는 텐서를 따로 gpu에 올려주는 작업을 해야한다. 그러나 PyTorch는 기본적으로는 cpu를 사용한다. 그러나 딥러닝 관련 연구나 프로젝트를 수행하려는 사람들은 gpu를 가진 경우가 많을 것이다. 따라서 웬만하면 gpu를 사용하는 것이 더 좋으므로 gpu를 default로 설정하는 게 낫다. 또한 나의 경우에는 메모리를 좀 더 차지하더라도 정밀하게 계산했으면 좋겠어서 double형 (또는 float64형)을 기본적으로 사용하고 싶었다. 이 글에서 다루는 내용은 다음과 같다. 1. Tensor를 gpu에서 사용하도록 하는 방법 2. Default 설정을 바꿔서 gpu를 쓰도록 지정하는 방법 1. Tensor를 gpu에서 사용하도록 하는 방법 tensor를..
PyTorch에서 텐서끼리의 곱이 나와있는데 그 규칙을 알기 위해 이것저것 해본 것을 기록한 글이다. 여기서는 PyTorch의 matmul만 다룬다. https://pytorch.org/docs/stable/generated/torch.matmul.html?highlight=matmul#torch.matmul torch.matmul — PyTorch 1.12 documentation Shortcuts pytorch.org 다음 글을 보면 1차원 텐서(벡터)나 2차원 텐서(행렬) 곱은 이해하기 어렵지 않다. 맨 마지막 항목에 주목해야한다. 맨 마지막 항목이 두 텐서 중 하나는 1차원 이상, 다른 하나는 N(>3)차원 이상일 때의 곱을 나타낸 것이다. 여기서 미리 알아야할 것 :: Tensor에서 첫 번째 ..
이미지 분류기를 테스트하는 과정에서 matplotlib을 쓰면 커널이 자꾸 죽는 현상이 발견되었다. 아나콘다 프롬프트를 보면 다음과 같은 에러를 확인하였고, 아래의 참고 링크를 통해서 문제를 해결했다. [I 19:30:40.558 NotebookApp] Kernel started: d0c3b529-6a30-422b-a296-d963b18e4149, name: python3 OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program..