Skip to content

Instantly share code, notes, and snippets.

numpy==1.21.5
pandas==1.3.5
matplotlib==3.5.1
scipy==1.7.3
scikit-learn==1.0.2

FROM pytorch/pytorch:1.9.0-cuda10.2-cudnn7-runtime

RUN mkdir /app

COPY requirements.txt /app

WORKDIR /app

RUN python -m pip install - upgrade pip && pip install -r requirements.txt && rm -rf requirements.txt

@dongqifong
dongqifong / image_building.md
Last active March 25, 2022 15:58
build docker image

Run docker image and execute run.py

$ docker run --rm -it --init --gpus=all -v <絕對路徑>:/app --name <container_name> <image_name:tag> python run.py

e.g.

$ docker run --rm -it --init --gpus=all -v C:\Users\user\Desktop\docker\pytorch:/app --name container1 torch-gpu-1.9:0.1.0 python run.py

model.eval() # 取消dropout or batch normalization
with torch.no_grad(): # 不計算梯度
predict = []
for data, labels in test_loader:
# Forward
out = model(data)
predict.append(out.numpy())
model.train() # 重新開啟dropout or batch normalization
@dongqifong
dongqifong / training.py
Last active July 2, 2021 13:06
pytorch_training
# model object
model = MyModel()
# define lr, optimizer, loss function
lr = 0.001
optimizer = torch.optim.Adam(model.parameters(), lr=lr)
loss_function = nn.CrossEntropyLoss()
# Train
epochs = 100
@dongqifong
dongqifong / MyModel.py
Created July 2, 2021 12:55
pytorch_Model_medium
class MyModel(nn.Module):
def __init__(self):
super(MyModel, self).__init__()
# Encoder
self.block1 = nn.Sequential(
nn.Linear(128,64),
nn.Tanh(),
nn.Linear(64, 32),
nn.Tanh(),
nn.Linear(32, 16),