deeplearningzerotoall / pytorch Goto Github PK
View Code? Open in Web Editor NEWDeep Learning Zero to All - Pytorch
Deep Learning Zero to All - Pytorch
device = 'cuda' if torch.cuda.is_available() else 'cpu'
위 코드 실행 시, device 가 ('cuda',) 로 출력되어,
이후 CNN().to(device) 등의 to(device) 실행 시 오류가 출력됩니다.
(to() received an invalid combination of arguments - got (tuple))
device ="cuda" if torch.cuda.is_available() else "cpu"
위 코드로 변경 후 실행 시 오류 없이 나오네요.
별거 아니지만, 혹시 유사한 에러 있으신 분은 참고하시면 좋을 것 같습니다.
참고로 제 환경은 torch 1.1.0, conda 4.6 입니다.
PyTorch also has F.nll_loss() function that computes the negative loss likelihood.
= > PyTorch also has F.nll_loss() function that computes the negative log likelihood.
bottleneck 클라스에서 self.stride = stride를 선언하신 이유를 모르겠습니다. 오타인가요??
diff = y_pred - Y
# Back prop (chain rule)
d_l2 = diff * sigmoid_prime(l2)
위 부분에서 diff를 그대로 쓰면 안될거 같습니다.
diff가 loss를 의미하는데, 저 자리에는 diff가 아니라 d(diff)/d(y_pred) => 1이 되야할거 같습니다.
제가 잘못 이해했다면 알려주시면 감사하겠습니다.
업데이트 부분에서
w1 = w1 - learning_rate * d_w1
b1 = b1 - learning_rate * torch.mean(d_b1, 0)
왜 bias에만 mean을 적용하는지 가르쳐주세요 그리고 torch.mean(d_b1, 0) 대신 d_b1했을때도 결과가 같은데요.
3.그리고 마지막 셀에서 끝나지 않는데,, 저만 그런가요
import torch
device = 'gpu' if torch.cuda.is_available() else 'cpu'
x =torch.rand(3).to(device)
x.device
output:
device(type='cpu')
이런 식으로 하는게 좋을까요?
아니면 조금더 깔끔하게 cpu 사용을 default 로 하고, gpu 사용할 것만 to(device) 로 전달 할까요?
안녕하세요
nvidia-docker를 이용해서
--device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm
gpu device들을 연결시켜주고 실행을 시켰는데,
python -c "from tensorflow.python.client import device_lib; local_device_protos = device_lib.list_local_devices(); print([x.name for x in local_device_protos if x.device_type == 'GPU'])"
명령어를 입력하였을 때,
2019-05-23 23:26:34.907318: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-05-23 23:26:34.937638: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2399875000 Hz
2019-05-23 23:26:34.943818: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x55c7c3ae6970 executing computations on platform Host. Devices:
2019-05-23 23:26:34.943838: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): ,
gpu는 못찾고 cpu만 나와서 예제 코드를 실습할 때도 cpu를 이용해서 학습을 하고 있습니다.
tensorflow/tensorflow:latest-gpu-py3 도커 이미지를 이용하였을 때는
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:02:00.0
totalMemory: 10.92GiB freeMemory: 10.76GiB
2019-05-23 14:25:30.391164: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 1 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:03:00.0
totalMemory: 10.92GiB freeMemory: 10.76GiB
라고 뜨면서 정상 작동하는 걸 볼 수 있었습니다.
gpu를 도커에서 사용하려면 이 외 어떤 방법이 있나요?
# 다른 숫자도 상관없을듯 합니다
torch.manual_seed(777)
np.random.seed(777)
파일구조 통일: 여러 방법이 있습니다. (선택이 필요합니다)
criterion(loss_function) 과 optimizer 를 밖으로 꺼낼 것인가? 아니면 모델 안에 내장할 것인가?
# CNN lab-11-3
# define cost/loss & optimizer
self.criterion = torch.nn.CrossEntropyLoss() # Softmax is internally computed.
self.optimizer = torch.optim.Adam(self.parameters(), lr=learning_rate)
# CNN lab-09-3
criterion = torch.nn.BCELoss().to(device)
optimizer = torch.optim.SGD(model.parameters(), lr=1) # modify learning rate 0.1 to 1
linear를 1~5까지 만들어 놓고 이렇게 모델을 생성하는게 맞는건가요?
# model
model = torch.nn.Sequential(linear1, relu, linear2, relu, linear3).to(device)``
Lab04-02 실습 코드에서 customdataset와 dataloader에 관련되어 강의에서 나왔던 코드가 업로드되어있지 않은건가요?
PDF 파일의 경우에는 여기에 올리고 GIT-LFS 로 tracking 하면 어떤가요?
jupyter-core와 notebook을 추가로 설치해야
jupyter nootbook이 정상 실행되네요.
안녕하세요. 강의 잘 보고있습니다.
Jupyter Notebook Lab에 있는 표기법에 질문이 있습니다.
'Naive Data Representation' 에 다음과 같은 코드가 있습니다.
# 데이터
x1_train = torch.FloatTensor([[73], [93], [89], [96], [73]])
x2_train = torch.FloatTensor([[80], [88], [91], [98], [66]])
x3_train = torch.FloatTensor([[75], [93], [90], [100], [70]])
y_train = torch.FloatTensor([[152], [185], [180], [196], [142]])
저 같은 경우는 이 코드에서 x1_train
라는걸 직관적으로 보면 train dataset의 첫 번째 데이터 라고 생각이 드는데 여기에서는 x1_train
이 데이터의 첫 번째 차원을 의미하는 것으로 이해했습니다. 일반적으로 사용하는 표기방식이 따로 있는지 궁금합니다.
# Cost 계산 (1)
hypothesis = F.softmax(x_train.matmul(W) + b, dim=1) # or .mm or @
y_one_hot = torch.zeros_like(hypothesis)
y_one_hot.scatter_(1, y_train.unsqueeze(1), 1)
cost = (y_one_hot * -torch.log(F.softmax(hypothesis, dim=1))).sum(dim=1).mean()
# cost로 H(x) 개선
optimizer.zero_grad()
cost.backward()
optimizer.step()
# 100번마다 로그 출력
if epoch % 100 == 0:
print('Epoch {:4d}/{} Cost: {:.6f}'.format(
epoch, nb_epochs, cost.item()
))
위와 같이 16번째 쉘의 cost 함수를 계산하는 부분에 softmax가 2번 들어간 것으로 확인됩니다.
물론 2번 넣어도 계산이 잘 되겠지만, 의도하신건지 궁금합니다.
감사합니다.
해당 레파지토리의 유저 가이드(https://github.com/deeplearningzerotoall/PyTorch/blob/master/docker_user_guide.md) 를 따라서 conda 업데이트 및 requirements.txt 상에 있는 패키지들을 모두 설치한 후에 jupyter를 실행시키면 실행이 되지 않습니다. (ModuleNotFoundError: No module named 'jupyter_core')
혹시나 pip list를 쳐보니 jupyter가 목록에 없었습니다.
requirements.txt를 수정해주셔야 할 듯 합니당
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.