This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ddd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOG_DIR = '"./drive/My Drive/log/"' | |
get_ipython().system_raw( | |
'tensorboard --logdir {} --host 0.0.0.0 --port 6006 &' | |
.format(LOG_DIR) | |
) | |
writer = SummaryWriter(log_dir='./drive/My Drive/log/runs/test-1') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
epochs = 5 | |
steps = 0 | |
running_loss = 0 | |
print_every = 10 | |
writer = SummaryWriter(log_dir='./log/runs/test-1') | |
for epoch in range(epochs): | |
for inputs, labels in trainloader: | |
steps += 1 | |
# Move input and label tensors to the default device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To GPU | |
model.to(device) | |
criterion = nn.CrossEntropyLoss() | |
# Only train the classifier parameters, feature parameters are frozen | |
optimizer = optim.Adam(model.classifier.parameters()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num_classes = 2 | |
model.classifier = nn.Sequential( | |
nn.Dropout(p=0.1), | |
nn.Conv2d(512, num_classes, kernel_size=(1, 1), stride=(1, 1)), | |
nn.ReLU(), | |
nn.AvgPool2d(kernel_size=13, stride=1, padding=0) | |
) | |
model.num_classes = num_classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use GPU if it's available | |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
model = models.squeezenet1_1(pretrained=True) | |
# Freeze parameters so we don't backprop through them | |
for param in model.parameters(): | |
param.requires_grad = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_dir = 'Cat_Dog_data' | |
# TODO: Define transforms for the training data and testing data | |
train_transforms = transforms.Compose([transforms.RandomRotation(30), | |
transforms.RandomResizedCrop(224), | |
transforms.RandomHorizontalFlip(), | |
transforms.ToTensor(), | |
transforms.Normalize([0.485, 0.456, 0.406], | |
[0.229, 0.224, 0.225])]) | |
test_transforms = transforms.Compose([transforms.Resize(255), | |
transforms.CenterCrop(224), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip | |
!unzip ngrok-stable-linux-amd64.zip | |
LOG_DIR = './log' # '"./drive/My Drive/log/"' for Drive location | |
get_ipython().system_raw( | |
'tensorboard --logdir {} --host 0.0.0.0 --port 6006 &' | |
.format(LOG_DIR) | |
) | |
import time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://pytorch.org/ | |
from os.path import exists | |
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag | |
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag()) | |
cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\.\([0-9]*\)\.\([0-9]*\)$/cu\1\2/' | |
accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu' | |
!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.1-{platform}-linux_x86_64.whl torchvision |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*Programming. The metaphysics way.*, exercises for | |
================================================== | |
Class 1-alpha | |
------------- | |
We covered lambda calculus, some common operators, defining functions, using `.hs` files and GHCi and just barely scratched data types (GADTs; the `data Bool = False | True` part). | |
So here are some refreshers and clarifications for that, as well as something to go a bit further on with. |
NewerOlder