Commit 67a83738 authored by okiss's avatar okiss
Browse files

Update CNN.py

parent 34d8a3e1
......@@ -49,8 +49,10 @@ def run(trainX, trainY):
save_model_param(pytorch=True)
def train(trainloader, net, optimizer, criterion, epoch=50):
loss=[]
for epoch in range(2): # loop over the dataset multiple times
running_loss = 0.0
loss_values=[]
for i, data in enumerate(trainloader, 0):
# get the inputs; data is a list of [inputs, labels]
inputs, labels = data
......@@ -63,12 +65,16 @@ def train(trainloader, net, optimizer, criterion, epoch=50):
loss = criterion(outputs, labels.squeeze(1))
loss.backward()
optimizer.step()
# print statistics
running_loss += loss.item()
run_loss = loss.item()
running_loss+=run_loss
loss_values.append(run_loss)
if i % 200 == 0: # print every 200 mini-batches
print('[%d, %5d] loss: %.3f' %
(epoch + 1, i + 1, running_loss / 200))
running_loss = 0.0
los=np.mean(loss_values)
loss.append(los)
return loss
print('Finished Training')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment