본문 바로가기
728x90

AI-Tech 부스트캠프42

[PyTorch] (B,C,H,W) 이어 붙이기 tensor.randn((B,) + (C,H,W)) CNN을 이용하여 Image Classification하는 훈련 train을 시킬 때 데이터를 (배치사이즈(B), 채널(C), 높이(H), 너비(W))를 차례대로 텐서의 크기를 맞춰서 코드를 작성해야할 때가 있다. 이때 배치사이즈만 따로 떨어져 있는 때가 있다. 이 때 tensor.randn((B,) + (C,H,W))를 이용하면 tensor((B,C,H,W)) 사이즈라는 것을 알릴 수 있다. 예제 # x_dim = (1,28,28) batch_in.view(-1,x_dim) #(batch_size, 1 * 28 * 28) batch_in.view((-1,)+x_dim) #(batch_size, 1, 28, 28) 2023. 11. 9.
torch.Tensor.item https://pytorch.org/docs/stable/generated/torch.Tensor.item.html torch.Tensor.item — PyTorch 2.1 documentation Shortcuts pytorch.org 모델에서 예측한 값(y_pred)과 참 값(y_trgt)값이 같은 것의 개수를 구하려 할 때 (y_pred==y_trgt).sum().item()을 쓰는 코드를 발견해서 디버깅을 해보면서 torch.Tensor.item()이 텐서 값을 숫자만으로 나타낼 수 있다는 것을 알았다. 이는 dictionary에서 (key, value) 값으로 나타내는 items과 다른 의미를 나타낼 수 있다는 것을 알았다. python items code car = { "brand": "BMW.. 2023. 11. 9.
torch.stack() 과 torch.cat() torch.stack() 과 torch.cat() 모두 행렬을 연결하는데 쓰인다. 하지만 둘의 다른점을 비교하지 않으면 가끔 혼란스러울 수 있다. 따라서 한번 정리하고 넘어가려 한다. torch.cat()은 주어진 차원을 기준으로 주어진 텐서들을 연결(concatenate)한다. torch.stack()은 새로운 차원으로 주어진 텐서들을 연결한다. import torch x = torch.FloatTensor([1,4]) y = torch.FloatTensor([2,5]) z = torch.FloatTensor([3,6]) print(x.shape) #torch.Size([2]) print(torch.stack([x,y,z])) # tensor([[1., 4.], # [2., 5.], # [3., 6.].. 2023. 4. 8.
Elasticsearch (엘라스틱서치) Elasticsearch Elasticsearch는 비정형 데이터 검색에 최적화된 데이터베이스(search engine)이다. Elasticsearch의 기원 런던의 아파트에서 살고 있는 Shay Banon은 구직중 남는 시간에 아내의 요리법 목록을 위한 검색 엔진을 만들었다. 이 최초의 버전이 컴파스(Compass ,2004)이고, 두번째 버전이 Elasticsearch(2010)이다. Elasticsearch와 관련된 용어들 시스템 아키텍트가 신경써야 할 부분 Cluster Node Shard Replica 내(데이터 엔지니어)가 신경써야 할 부분 Index Documents Mappings Analyzer Scoring 관계형 데이터베이스(RDB) VS 엘라스틱 서치(Elasticsearch) 관계.. 2023. 1. 20.
728x90