Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrei-Claudiu Roibu
BrainMapper
Commits
f982dfaf
Commit
f982dfaf
authored
Apr 16, 2020
by
Andrei-Claudiu Roibu
🖥
Browse files
debugging + commenting out functions deprecated
parent
92dfa3ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
solver.py
View file @
f982dfaf
...
...
@@ -50,7 +50,7 @@ class Solver():
logs_directory (str): Directory for outputing training logs
Returns:
trained model
(?)
- working on this!
trained model - working on this!
"""
...
...
@@ -105,8 +105,8 @@ class Solver():
self
.
start_epoch
=
1
self
.
start_iteration
=
1
self
.
best_mean_score
=
0
self
.
best_mean_score_epoch
=
0
#
self.best_mean_score = 0
#
self.best_mean_score_epoch = 0
self
.
LogWriter
=
LogWriter
(
number_of_classes
=
number_of_classes
,
logs_directory
=
logs_directory
,
...
...
@@ -159,8 +159,8 @@ class Solver():
print
(
'-> Phase: {}'
.
format
(
phase
))
losses
=
[]
outputs
=
[]
y_values
=
[]
#
outputs = []
#
y_values = []
if
phase
==
'train'
:
model
.
train
()
...
...
@@ -196,9 +196,11 @@ class Solver():
iteration
+=
1
losses
.
append
(
loss
.
item
())
outputs
.
append
(
torch
.
max
(
y_hat
,
dim
=
1
)[
1
].
cpu
())
y_values
.
append
(
y
.
cpu
())
#
outputs.append(torch.max(y_hat, dim=1)[1].cpu())
#
y_values.append(y.cpu())
# Clear the memory
...
...
@@ -212,24 +214,25 @@ class Solver():
print
(
"100%"
,
flush
=
True
)
with
torch
.
no_grad
():
output_array
,
y_array
=
torch
.
cat
(
outputs
),
torch
.
cat
(
y_values
)
#
output_array, y_array = torch.cat(
#
outputs), torch.cat(y_values)
self
.
LogWriter
.
loss_per_epoch
(
losses
,
phase
,
epoch
)
dice_score_mean
=
self
.
LogWriter
.
dice_score_per_epoch
(
phase
,
output_array
,
y_array
,
epoch
)
if
phase
==
'test'
:
if
dice_score_mean
>
self
.
best_mean_score
:
self
.
best_mean_score
=
dice_score_mean
self
.
best_mean_score_epoch
=
epoch
index
=
np
.
random
.
choice
(
len
(
dataloaders
[
phase
].
dataset
.
X
),
size
=
3
,
replace
=
False
)
self
.
LogWriter
.
sample_image_per_epoch
(
prediction
=
model
.
predict
(
dataloaders
[
phase
].
dataset
.
X
[
index
],
self
.
device
),
ground_truth
=
dataloaders
[
phase
].
dataset
.
y
[
index
],
phase
=
phase
,
epoch
=
epoch
)
# dice_score_mean = self.LogWriter.dice_score_per_epoch(
# phase, output_array, y_array, epoch)
# if phase == 'test':
# if dice_score_mean > self.best_mean_score:
# self.best_mean_score = dice_score_mean
# self.best_mean_score_epoch = epoch
# index = np.random.choice(
# len(dataloaders[phase].dataset.X), size=3, replace=False)
# self.LogWriter.sample_image_per_epoch(prediction=model.predict(dataloaders[phase].dataset.X[index], self.device),
# ground_truth=dataloaders[phase].dataset.y[index],
# phase=phase,
# epoch=epoch)
print
(
"Epoch {}/{} DONE!"
.
format
(
epoch
,
self
.
number_epochs
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment