Skip to content

Commit bee2872

Browse files
committed
Dependencies for pip python 2 deleted, symlink created for pip python 3, main src structure added as a placeholder
1 parent f23fb83 commit bee2872

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2222
unzip \
2323
zip \
2424
libzmq3-dev \
25-
python-dev \
26-
python-numpy \
2725
python3-dev \
2826
python3-numpy \
29-
python-pip \
3027
python3-pip \
31-
python-tk \
3228
python3-tk \
3329
libtbb2 \
3430
libtbb-dev \
@@ -106,8 +102,7 @@ RUN cargo install fd-find ripgrep
106102

107103

108104
# Symlink for pip3
109-
# RUN sudo ln -s /usr/bin/pip3 /usr/bin/pip
105+
RUN sudo ln -s /usr/bin/pip3 /usr/bin/pip
110106

111107
#Pytorch
112-
RUN sudo pip3 install https://download.pytorch.org/whl/cu100/torch-1.3.1%2Bcu100-cp36-cp36m-linux_x86_64.whl
113-
RUN sudo pip3 install torchvision
108+
RUN sudo pip install torch torchvision

src/main/main.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import numpy as np
2+
import torch
3+
import torch.optim as optim
4+
import torch.nn as nn
5+
# Data Generation
6+
np.random.seed(42)
7+
x = np.random.rand(100, 1)
8+
y = 1 + 2 * x + .1 * np.random.randn(100, 1)
9+
10+
# Shuffles the indices
11+
idx = np.arange(100)
12+
np.random.shuffle(idx)
13+
14+
# Uses first 80 random indices for train
15+
train_idx = idx[:80]
16+
# Uses the remaining indices for validation
17+
val_idx = idx[80:]
18+
19+
# Generates train and validation sets
20+
x_train, y_train = x[train_idx], y[train_idx]
21+
x_val, y_val = x[val_idx], y[val_idx]
22+
23+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
24+
25+
# Our data was in Numpy arrays, but we need to transform them into PyTorch's Tensors
26+
# and then we send them to the chosen device
27+
x_train_tensor = torch.from_numpy(x_train).float().to(device)
28+
y_train_tensor = torch.from_numpy(y_train).float().to(device)
29+
30+
# Here we can see the difference - notice that .type() is more useful
31+
# since it also tells us WHERE the tensor is (device)
32+
print(type(x_train), type(x_train_tensor), x_train_tensor.type())
33+
34+
print("=============================================")
35+
print(" x-train ")
36+
print("=============================================")
37+
print(x_train)
38+
39+
print("=============================================")
40+
print(" train-tensor ")
41+
print("=============================================")
42+
print(x_train_tensor)

0 commit comments

Comments
 (0)