Skip to content

Instantly share code, notes, and snippets.

View Kulikovpavel's full-sized avatar
💭
Tech Lead@Hello-Cash-Ltd

Pavel Kulikov Kulikovpavel

💭
Tech Lead@Hello-Cash-Ltd
View GitHub Profile
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')
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
# To GPU
model.to(device)
criterion = nn.CrossEntropyLoss()
# Only train the classifier parameters, feature parameters are frozen
optimizer = optim.Adam(model.classifier.parameters())
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
# 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
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),
!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
# 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
@Kulikovpavel
Kulikovpavel / programming_metaphysics.1-alpha.lhs
Created June 24, 2017 07:02 — forked from wldhx/programming_metaphysics.1-alpha.lhs
goto-school-2017-06.programming_metaphysics.1-alpha
*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.