Taller - 02 - Taller - Ipynb - DarwinMerchan
Taller - 02 - Taller - Ipynb - DarwinMerchan
Importando bibliotecas
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms
use_cuda = torch.cuda.is_available()
device = torch.device("cuda" if use_cuda else "cpu")
train_kwargs = {'batch_size': 500}
test_kwargs = {'batch_size': 500}
if use_cuda:
cuda_kwargs = {'num_workers': 1, 'pin_memory': True, 'shuffle': True}
train_kwargs.update(cuda_kwargs)
test_kwargs.update(cuda_kwargs)
use_cuda
False
Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz
Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz to ../data/MNIST/raw/train-images-idx3-ubyte.gz
100%|██████████| 9912422/9912422 [00:00<00:00, 107951287.72it/s]
Extracting ../data/MNIST/raw/train-images-idx3-ubyte.gz to ../data/MNIST/raw
Downloading http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz
Downloading http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz to ../data/MNIST/raw/train-labels-idx1-ubyte.gz
100%|██████████| 28881/28881 [00:00<00:00, 31044514.05it/s]
Extracting ../data/MNIST/raw/train-labels-idx1-ubyte.gz to ../data/MNIST/raw
Downloading http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz
Downloading http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz to ../data/MNIST/raw/t10k-images-idx3-ubyte.gz
100%|██████████| 1648877/1648877 [00:00<00:00, 39908199.29it/s]Extracting ../data/MNIST/raw/t10k-images-idx3-ubyte.gz to ../data/MNIST/raw
Downloading http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz
Downloading http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz to ../data/MNIST/raw/t10k-labels-idx1-ubyte.gz
100%|██████████| 4542/4542 [00:00<00:00, 14688148.63it/s]
Extracting ../data/MNIST/raw/t10k-labels-idx1-ubyte.gz to ../data/MNIST/raw
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10)
Main execution
model = Net().to(device)
optimizer = torch.optim.Adadelta(model.parameters(), lr=1.0)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=1, gamma=0.7)
for epoch in range(5):
train(model, device, train_loader, optimizer, epoch)
test(model, device, test_loader)
scheduler.step()
keyboard_arrow_down Tarea 1
Entrenar la red convolucional pero esta vez con el conjunto de datos Fashion-MNIST
Entrenamiento 3 con 50 epocas Inicia con 83.91% y termina en 99.98%, desde la epoca 22 se mantiene en ese valor
Conclusión : El entrenamiento de esta red neuronal, puedo evidenciar que a mayor entrenamiento se desempeña mejor llegando a valores altos
como 99.98%
keyboard_arrow_down Tarea 2
Entrenar la red convolucional pero esta vez con el conjunto de datos CIFAR10
keyboard_arrow_down Execution
model = Net().to(device)
optimizer = torch.optim.Adadelta(model.parameters(), lr=1.0)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=1, gamma=0.7)
for epoch in range(5):
train(model, device, train_loader, optimizer, epoch)
test(model, device, test_loader)
scheduler.step()
CONCLUSION: en 3 entrenamientos no alcanzo niveles optimos, pero al estar en una plataforma free, cuando necesitaba entrenar a 100 para
ver el comportamiento me salio que ya no podia seguir entrenando por limites de conexión a GPU. Tambien pude apreciar que desde mi
maquina si se ejecuta pero el tiempo de respuesta es muy lento.
Despues de la ejecución del tercer entrenamiento , solo para presentar el taller volvi a enviar uno de 5 epocas. ya que el anterior se borro .
...