Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Public exercise material
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aia02506
Public exercise material
Commits
8a0ea7e5
Commit
8a0ea7e5
authored
2 years ago
by
papi
Browse files
Options
Downloads
Patches
Plain Diff
Type hints removed for better Python version compatibility
parent
c737d7f3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Chapter09/netEval.py
+16
-7
16 additions, 7 deletions
Chapter09/netEval.py
Chapter09/sampleNetwork.py
+3
-4
3 additions, 4 deletions
Chapter09/sampleNetwork.py
with
19 additions
and
11 deletions
Chapter09/netEval.py
+
16
−
7
View file @
8a0ea7e5
...
@@ -11,20 +11,29 @@ import os
...
@@ -11,20 +11,29 @@ import os
import
glob
import
glob
import
skimage.io
import
skimage.io
import
time
import
time
from
collections.abc
import
Callable
from
sampleNetwork
import
netFunc
from
sampleNetwork
import
netFunc
def
netEval
(
netFunc
:
Callable
[
np
.
array
]
,
dataPath
:
str
,
targetPath
:
str
)
->
tuple
[
float
,
float
]
:
def
netEval
(
netFunc
,
dataPath
,
targetPath
)
:
"""
'''
Evaluates the accuracy of a classification model using provided dataset.
Evaluates the accuracy of a classification model using provided dataset.
Parameters
Parameters
----------
----------
netFunc - function of the network that takes an image and outputs a predicted class,
\n
netFunc : function
dataPath - path to a folder with data,
\n
Function of the network that takes an image and outputs a predicted class
targetPath - path to a file with target labels (either .txt or .npy).
dataPath: string
"""
Path to a folder with data
targetPath: string
Path to a file with target labels (either .txt or .npy)
Returns
-------
accuracy: float
Accuracy of the network on provided dataset
execTime:
Network prediction execution time
'''
assert
callable
(
netFunc
),
"
The first argument is not callable, it should be a network function.
"
assert
callable
(
netFunc
),
"
The first argument is not callable, it should be a network function.
"
assert
os
.
path
.
exists
(
dataPath
),
f
"
Provided path:
{
dataPath
}
does not exist.
"
assert
os
.
path
.
exists
(
dataPath
),
f
"
Provided path:
{
dataPath
}
does not exist.
"
...
...
This diff is collapsed.
Click to expand it.
Chapter09/sampleNetwork.py
+
3
−
4
View file @
8a0ea7e5
...
@@ -5,9 +5,8 @@ Created on Tue Mar 28 14:31:20 2023
...
@@ -5,9 +5,8 @@ Created on Tue Mar 28 14:31:20 2023
@author: Pawel Pieta, papi@dtu.dk
@author: Pawel Pieta, papi@dtu.dk
"""
"""
import
numpy
as
np
import
numpy
as
np
from
collections.abc
import
Iterable
def
netFunc
(
images
:
np
.
array
)
->
Iterable
[
int
]
:
def
netFunc
(
images
)
:
'''
'''
Loads a feed forward neural network, and predicts the labels of each image in an array.
Loads a feed forward neural network, and predicts the labels of each image in an array.
...
@@ -16,8 +15,8 @@ def netFunc(images: np.array) -> Iterable[int]:
...
@@ -16,8 +15,8 @@ def netFunc(images: np.array) -> Iterable[int]:
images : numpy array
images : numpy array
An array with grayscale images loaded with
"
skimage.io.imread(fname,as_gray=True)
"
,
An array with grayscale images loaded with
"
skimage.io.imread(fname,as_gray=True)
"
,
float datatype with pixel values between 0 and 1. The array has
\n
float datatype with pixel values between 0 and 1. The array has
\n
dimension N x H x W x C where N is the number of images, H is the height of the images
\n
dimension N x H x W x C where N is the number of images, H is the height of the images
,
\n
,
W is the width of the images and C is the number of channels in each image.
W is the width of the images and C is the number of channels in each image.
Returns
Returns
-------
-------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment