Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
62038bb5
Commit
62038bb5
authored
7 years ago
by
Luise Odenthal
Browse files
Options
Downloads
Patches
Plain Diff
debuged test and init for comparison
parent
394c53bc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
navipy/comparing/__init__.py
+30
-18
30 additions, 18 deletions
navipy/comparing/__init__.py
navipy/comparing/test.py
+41
-22
41 additions, 22 deletions
navipy/comparing/test.py
with
71 additions
and
40 deletions
navipy/comparing/__init__.py
+
30
−
18
View file @
62038bb5
...
...
@@ -6,6 +6,7 @@ memorised places.
import
numpy
as
np
from
navipy.processing.tools
import
is_ibpc
,
is_obpc
def
is_numeric_array
(
array
):
"""
Checks if the dtype of the array is numeric.
...
...
@@ -53,9 +54,7 @@ def check_scene(scene):
assert
len
(
scene
.
shape
)
==
3
assert
~
(
scene
.
shape
[
1
]
<=
0
)
assert
~
(
scene
.
shape
[
0
]
<=
0
)
assert
(
scene
.
shape
[
2
]
==
4
)
assert
(
scene
.
shape
[
3
]
==
1
)
# assert ~(np.any(np.isNone(scene)))
assert
(
scene
.
shape
[
2
]
==
1
)
def
simple_imagediff
(
current
,
memory
):
...
...
@@ -77,8 +76,8 @@ the current and memorised place code
'
memory place code should be a numpy array
'
assert
np
.
all
(
current
.
shape
==
memory
.
shape
),
\
'
memory and current place code should have the same shape
'
assert
check_scene
(
current
)
assert
check_scene
(
memory
)
check_scene
(
current
)
check_scene
(
memory
)
diff
=
current
-
memory
if
is_ibpc
(
current
):
return
diff
...
...
@@ -95,7 +94,7 @@ the current and memorised place code
:param current: current place code
:param memory: memorised place code
:returns: the image difference
:rtype: float
:rtype: float
#array(1,4) for ibpc and float for obpc
..ref: Zeil, J., 2012. Visual homing: an insect perspective.
Current opinion in neurobiology
...
...
@@ -107,11 +106,11 @@ the current and memorised place code
'
memory place code should be a numpy array
'
assert
np
.
all
(
current
.
shape
==
memory
.
shape
),
\
'
memory and current place code should have the same shape
'
assert
check_scene
(
current
)
assert
check_scene
(
memory
)
check_scene
(
current
)
check_scene
(
memory
)
diff
=
np
.
power
(
current
-
memory
,
2
)
if
is_ibpc
(
current
):
return
np
.
sqrt
(
diff
.
mean
(
axis
=
0
).
mean
(
axis
=
1
))
return
np
.
sqrt
(
diff
.
mean
(
axis
=
0
).
mean
(
axis
=
0
))
# 1
elif
is_obpc
(
current
):
return
np
.
sqrt
(
diff
.
mean
(
axis
=
0
).
mean
(
axis
=
0
))
else
:
...
...
@@ -134,26 +133,39 @@ the current and memorised place code.
"""
assert
is_ibpc
(
current
),
\
'
The current and memory place code should be image based
'
assert
check_scene
(
current
)
assert
check_scene
(
memory
)
ridf
=
np
.
zeros
(
current
.
shape
[
1
])
assert
is_ibpc
(
memory
),
\
'
The current and memory place code should be image based
'
check_scene
(
current
)
check_scene
(
memory
)
ridf
=
np
.
zeros
((
current
.
shape
[
1
],
current
.
shape
[
2
]))
for
azimuth_i
in
range
(
0
,
current
.
shape
[
1
]):
rot_im
=
np
.
roll
(
current
,
azimuth_i
,
axis
=
1
)
r
ot_im
[
azimuth_i
]
=
imagediff
(
rot_im
,
memory
)
r
idf
[
azimuth_i
,
:
]
=
np
.
squeeze
(
imagediff
(
rot_im
,
memory
)
)
# rot_im
return
ridf
def
diff_optic_flow
(
current
,
memory
):
currrol
=
np
.
roll
(
current
,
1
,
axis
=
1
)
def
diff_optic_flow
(
current
,
memory
):
print
(
"
shape of current
"
,
current
.
shape
)
assert
is_ibpc
(
current
),
\
'
The current and memory place code should be image based
'
assert
is_ibpc
(
memory
),
\
'
The current and memory place code should be image based
'
check_scene
(
current
)
check_scene
(
memory
)
currroll
=
np
.
roll
(
current
,
1
,
axis
=
1
)
dx
=
current
-
currroll
memr
r
ol
=
np
.
roll
(
memory
,
1
,
axis
=
1
)
memro
l
l
=
np
.
roll
(
memory
,
1
,
axis
=
1
)
dy
=
memory
-
memroll
dy
=
np
.
reshape
(
dy
,
(
np
.
prod
(
dy
.
shape
),
1
))
dx
=
np
.
reshape
(
dx
,
(
np
.
prod
(
dx
.
shape
),
1
))
di
=
current
-
memory
di
=
np
.
reshape
(
di
,
(
np
.
prod
(
di
.
shape
),
1
))
A
=
np
.
column_stack
(
dy
,
dx
)
A
=
np
.
column_stack
(
[
dy
,
dx
]
)
ATA
=
np
.
dot
(
np
.
transpose
(
A
),
A
)
b
=
np
.
dot
(
np
.
transpose
(
A
),
di
)
res
=
n
umpy
.
linalg
.
solve
(
ATA
,
b
)
res
=
n
p
.
linalg
.
solve
(
ATA
,
b
)
return
res
def
gradient
(
current
,
memory
):
return
0
This diff is collapsed.
Click to expand it.
navipy/comparing/test.py
+
41
−
22
View file @
62038bb5
import
unittest
import
numpy
as
np
from
navipy.database
import
database
import
navipy.database
as
database
import
navipy.comparing
as
comparing
import
navipy.processing
as
processing
import
pkg_resources
...
...
@@ -59,13 +59,10 @@ class TestCase(unittest.TestCase):
# should be working -> check if result is correct
for
s
in
[
curr
]:
diff
=
comparing
.
imagediff
(
s
,
mem
)
self
.
assert
Fals
e
(
diff
.
shape
[
1
]
<
=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assert
Tru
e
(
diff
.
shape
[
1
]
=
=
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
def
test_imagediff_memory
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
...
...
@@ -85,8 +82,8 @@ class TestCase(unittest.TestCase):
# should be working -> check if result is correct
for
s
in
[
mem
]:
diff
=
comparing
.
imagediff
(
curr
,
s
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertFalse
(
diff
.
shape
[
0
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
==
1
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
...
...
@@ -108,13 +105,10 @@ class TestCase(unittest.TestCase):
# should be working -> check if result is correct
for
s
in
[
curr
]:
diff
=
comparing
.
rot_imagediff
(
s
,
mem
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertFalse
(
diff
.
shape
[
0
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
==
4
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
def
test_rotimagediff_memory
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
...
...
@@ -134,13 +128,10 @@ class TestCase(unittest.TestCase):
# should be working -> check if result is correct
for
s
in
[
mem
]:
diff
=
comparing
.
rot_imagediff
(
curr
,
s
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertFalse
(
diff
.
shape
[
0
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
==
4
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
def
test_simple_imagediff_curr
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
...
...
@@ -159,14 +150,38 @@ class TestCase(unittest.TestCase):
# should be working -> check if result is correct
for
s
in
[
curr
]:
diff
=
comparing
.
rot
_imagediff
(
s
,
mem
)
self
.
assertFalse
(
diff
.
shape
[
1
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
diff
=
comparing
.
simple
_imagediff
(
s
,
mem
)
self
.
assertFalse
(
diff
.
shape
[
0
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
self
.
assertTrue
(
diff
.
shape
[
0
]
>
0
)
def
test_simple_imagediff_mem
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
mem
=
processing
.
scene
(
self
.
mydb
,
rowid
=
2
)
curr2
=
curr
.
copy
()
curr2
[
3
,
5
,
2
,
0
]
=
np
.
nan
curr3
=
[[
1
,
2
,
3
],
[
1
,
2
,
3
],
[
1
,
2
,
3
]]
curr3
=
[
curr3
,
curr3
,
curr3
]
curr3
=
np
.
array
(
curr3
)
curr4
=
np
.
zeros
((
3
,
4
,
5
,
0
))
for
s
in
[
curr2
,
curr3
,
curr4
]:
# put useless stuff here
with
self
.
assertRaises
(
Exception
)
as
cm
:
comparing
.
simple_imagediff
(
s
,
mem
)
print
(
"
wanted exception occured
"
,
cm
.
exception
)
# should be working -> check if result is correct
for
s
in
[
mem
]:
diff
=
comparing
.
simple_imagediff
(
curr
,
s
)
self
.
assertFalse
(
diff
.
shape
[
0
]
<=
0
)
self
.
assertTrue
(
diff
.
shape
[
1
]
>
0
)
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
diff
)))
self
.
assertTrue
(
is_numeric_array
(
diff
))
self
.
assertTrue
(
diff
.
shape
[
2
]
==
4
)
self
.
assertTrue
(
diff
.
shape
[
3
]
==
1
)
def
test_diff_optic_flow_memory
(
self
):
curr
=
processing
.
scene
(
self
.
mydb
,
rowid
=
1
)
...
...
@@ -189,3 +204,7 @@ class TestCase(unittest.TestCase):
self
.
assertFalse
(
vec
.
shape
[
1
]
==
(
1
,
2
))
self
.
assertFalse
(
np
.
any
(
np
.
isnan
(
vec
)))
self
.
assertTrue
(
is_numeric_array
(
vec
))
if
__name__
==
'
__main__
'
:
unittest
.
main
()
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