Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
caries_classifier
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sjjsmuel
caries_classifier
Commits
088b9283
Commit
088b9283
authored
Jul 02, 2020
by
sjjsmuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
9dc2fcc7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
1 deletion
+59
-1
helpers/NoCAMModel.py
helpers/NoCAMModel.py
+58
-0
network/Resnet50.py
network/Resnet50.py
+1
-1
No files found.
helpers/NoCAMModel.py
0 → 100644
View file @
088b9283
from
tensorflow.keras
import
Model
from
tensorflow
import
GradientTape
,
cast
,
reduce_mean
,
reduce_sum
,
multiply
,
newaxis
,
reshape
,
transpose
,
squeeze
from
tensorflow.image
import
resize
from
tensorflow.math
import
multiply
,
reduce_min
,
reduce_max
,
divide
,
add
,
l2_normalize
from
tensorflow.linalg
import
matmul
import
tensorflow
as
tf
from
tensorflow.keras.losses
import
categorical_crossentropy
from
tensorflow.keras.metrics
import
CategoricalAccuracy
,
Mean
'''
Based on default example from Keras Docs.
https://keras.io/guides/customizing_what_happens_in_fit/
'''
metric_tracker
=
CategoricalAccuracy
()
loss_tracker
=
Mean
(
name
=
'loss'
)
class
NoCAMModel
(
Model
):
def
train_step
(
self
,
data
):
# Unpack the data. Its structure depends on your model and
# on what you pass to `fit()`.
x
,
y
=
data
img
=
x
[
'img'
]
mouth_filter
=
x
[
'mouth'
]
with
GradientTape
()
as
tape
:
y_pred
,
conv_out
=
self
(
img
,
training
=
True
)
# Forward pass
# Compute the loss value
loss
=
categorical_crossentropy
(
y
,
y_pred
)
# Compute gradients
trainable_vars
=
self
.
trainable_variables
gradients
=
tape
.
gradient
(
loss
,
trainable_vars
)
# Update weights
self
.
optimizer
.
apply_gradients
(
zip
(
gradients
,
trainable_vars
))
loss_tracker
.
update_state
(
loss
)
metric_tracker
.
update_state
(
y
,
y_pred
)
return
{
'loss'
:
loss_tracker
.
result
(),
'accuracy'
:
metric_tracker
.
result
()}
def
test_step
(
self
,
data
):
# Unpack the data
x
,
y
=
data
if
type
(
x
)
==
dict
:
x
=
x
[
'img'
]
# Compute predictions and skip the convolution output
y_pred
,
_
=
self
(
x
,
training
=
False
)
#calculate the loss
loss
=
categorical_crossentropy
(
y
,
y_pred
)
# Updates the metrics tracking the loss
loss_tracker
.
update_state
(
loss
)
# Update the metrics.
metric_tracker
.
update_state
(
y
,
y_pred
)
# Return a dict mapping metric names to current value.
return
{
'loss'
:
loss_tracker
.
result
(),
'accuracy'
:
metric_tracker
.
result
()}
\ No newline at end of file
network/Resnet50.py
View file @
088b9283
...
...
@@ -40,7 +40,7 @@ class Resnet50(NetworkBase):
if
cam
:
model
=
CAMModel
(
inputs
=
[
input_tensor
],
outputs
=
[
out
,
base_model
.
layers
[
-
1
].
output
])
else
:
model
=
Model
(
inputs
=
[
input_tensor
],
outputs
=
[
out
,
base_model
.
layers
[
-
1
].
output
])
model
=
NoCAM
Model
(
inputs
=
[
input_tensor
],
outputs
=
[
out
,
base_model
.
layers
[
-
1
].
output
])
return
model
Write
Preview
Markdown
is supported
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