Commit 2d2bdda9 authored by Simran Dave's avatar Simran Dave
Browse files

Upload New File

parent fc43603f
%% Cell type:code id: tags:
``` python
import torch
import numpy as np
import pandas as pd
import torch.nn as nn
import torch.optim as optim
import matplotlib.pyplot as plt
import torch.nn.functional as F
from torchsummary import summary
from torch.optim import lr_scheduler
from import DataLoader
from sklearn.model_selection import train_test_split
from models import *
%matplotlib inline
%% Cell type:code id: tags:
``` python
# hyper-parameters
# how many samples per batch to load
batch_size = 100
# percentage of training set to use as validation
valid_size = 0.1
# number of epochs to train the model
n_epochs = 30
# track change in validation loss
valid_loss_min = np.Inf
# specify the image classes
classes = ['noise', 'wave']
# gpu
DEVICE = torch.device('cuda: 3' if torch.cuda.is_available() else 'cpu')
%% Cell type:code id: tags:
``` python
# choose the training and test datasets
train_set = pd.read_csv("./output/train.csv", dtype=np.float32)
# Seperate the features and labels
total_train_label = train_set.label.values
total_train_data = train_set.loc[:, train_set.columns != 'label'].values
total_train_data = total_train_data.reshape(-1, 1, 4096)
# Split into training and test set
data_train, data_valid, label_train, label_valid = train_test_split(total_train_data, total_train_label, test_size=0.1, random_state=2)
%% Cell type:code id: tags:
``` python
# create feature and targets tensor for train set. As you remember we need variable to accumulate gradients. Therefore first we create tensor, then we will create variable
dataTrain = torch.from_numpy(data_train)
labelTrain = torch.from_numpy(label_train).type(torch.LongTensor) # data type is long
# create feature and targets tensor for valid set.
dataValid = torch.from_numpy(data_valid)
labelValid = torch.from_numpy(l