Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bob.io.stream
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
bob
bob.io.stream
Commits
30dc736b
Commit
30dc736b
authored
4 years ago
by
David GEISSBUHLER
Browse files
Options
Downloads
Patches
Plain Diff
handle slice properly
parent
6df3b1c3
No related branches found
No related tags found
1 merge request
!8
Accept file handle
Pipeline
#42646
passed
4 years ago
Stage: build
Changes
3
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
api_test.py
+26
-1
26 additions, 1 deletion
api_test.py
bob/io/stream/stream.py
+37
-7
37 additions, 7 deletions
bob/io/stream/stream.py
bob/io/stream/stream_file.py
+1
-1
1 addition, 1 deletion
bob/io/stream/stream_file.py
with
64 additions
and
9 deletions
api_test.py
+
26
−
1
View file @
30dc736b
...
@@ -2,6 +2,7 @@ from bob.io.stream import Stream, StreamFile, StreamFilter, stream_filter #, Str
...
@@ -2,6 +2,7 @@ from bob.io.stream import Stream, StreamFile, StreamFilter, stream_filter #, Str
import
numpy
as
np
import
numpy
as
np
import
bob.io.base
import
bob.io.base
# create data sets
# create data sets
num_frame
=
10
num_frame
=
10
...
@@ -40,7 +41,31 @@ assert(stream_b.timestamps == None)
...
@@ -40,7 +41,31 @@ assert(stream_b.timestamps == None)
assert
(
stream_a
.
camera
==
None
)
assert
(
stream_a
.
camera
==
None
)
assert
(
stream_b
.
camera
==
None
)
assert
(
stream_b
.
camera
==
None
)
print
(
stream_a
.
image_points
)
# load full datasets
ld_a
=
stream_a
.
load
()
ld_b
=
stream_b
.
load
()
assert
(
ld_a
.
shape
==
data_a
.
shape
)
assert
(
ld_b
.
shape
==
data_b
.
shape
)
assert
(
np
.
array_equal
(
ld_a
,
data_a
))
assert
(
np
.
array_equal
(
ld_b
,
data_b
))
# try some indices slices cases and compare data
tests
=
[
(
None
,
None
,
None
),
(
None
,
3
,
None
),
(
5
,
None
,
None
),
(
None
,
None
,
3
),
(
1
,
10
,
3
),
(
9
,
0
,
-
3
),
(
-
5
,
-
1
,
None
),
(
10
,
0
,
-
3
)]
for
t
in
tests
:
s
=
slice
(
t
[
0
],
t
[
1
],
t
[
2
])
dd
=
data_a
[
s
]
sd
=
stream_a
.
load
(
s
)
assert
(
np
.
array_equal
(
sd
,
dd
))
###########
###########
...
...
This diff is collapsed.
Click to expand it.
bob/io/stream/stream.py
+
37
−
7
View file @
30dc736b
...
@@ -128,7 +128,7 @@ class Stream:
...
@@ -128,7 +128,7 @@ class Stream:
raise
Exception
(
"
not yet implemented
"
)
raise
Exception
(
"
not yet implemented
"
)
# load one or several frames
# load one or several frames
def
load
(
self
,
index
):
def
load
(
self
,
index
=
None
):
indices
=
self
.
get_indices
(
index
)
indices
=
self
.
get_indices
(
index
)
# return buffered data OR load from file OR process data
# return buffered data OR load from file OR process data
if
self
.
__loaded
==
indices
and
self
.
__data
is
not
None
:
if
self
.
__loaded
==
indices
and
self
.
__data
is
not
None
:
...
@@ -141,20 +141,50 @@ class Stream:
...
@@ -141,20 +141,50 @@ class Stream:
self
.
__loaded
=
indices
self
.
__loaded
=
indices
return
self
.
__data
return
self
.
__data
# get list of indices
# get list of frame indices
# TODO check all cases
def
get_indices
(
self
,
index
):
def
get_indices
(
self
,
index
):
# None index is equivalent to [:] i.e. slice(None, None, None)
if
index
is
None
:
index
=
slice
(
None
,
None
,
None
)
# frame index transform to list
if
isinstance
(
index
,
int
):
if
isinstance
(
index
,
int
):
indices
=
[
index
]
indices
=
[
index
]
# slice transform to list
elif
isinstance
(
index
,
slice
):
elif
isinstance
(
index
,
slice
):
if
index
.
step
==
None
:
# start value: handle None and negative
indices
=
list
(
range
(
index
.
start
,
index
.
stop
))
if
index
.
start
is
not
None
:
if
index
.
start
<
0
:
start
=
self
.
shape
[
0
]
+
index
.
start
else
:
start
=
index
.
start
# boundary case
if
start
>=
self
.
shape
[
0
]:
start
=
self
.
shape
[
0
]
-
1
else
:
start
=
0
# stop value: handle None and negative
if
index
.
stop
is
not
None
:
if
index
.
stop
<
0
:
stop
=
self
.
shape
[
0
]
+
index
.
stop
else
:
stop
=
index
.
stop
# boundary case
if
stop
>=
self
.
shape
[
0
]:
stop
=
self
.
shape
[
0
]
-
1
else
:
stop
=
self
.
shape
[
0
]
# step value: handle None
if
index
.
step
is
not
None
:
step
=
index
.
step
else
:
else
:
indices
=
list
(
range
(
index
.
start
,
index
.
stop
,
index
.
step
))
step
=
1
# generate list
indices
=
list
(
range
(
start
,
stop
,
step
))
# pass lists thru
elif
isinstance
(
index
,
list
):
elif
isinstance
(
index
,
list
):
indices
=
index
indices
=
index
else
:
else
:
raise
Exception
(
"
index can only be int, slice
, tuple
or list
"
)
raise
Exception
(
"
index can only be
None,
int, slice or list
"
)
return
indices
return
indices
# filters
# filters
...
...
This diff is collapsed.
Click to expand it.
bob/io/stream/stream_file.py
+
1
−
1
View file @
30dc736b
...
@@ -51,7 +51,7 @@ class StreamFile:
...
@@ -51,7 +51,7 @@ class StreamFile:
else
:
else
:
# return a generic config if no config is present
# return a generic config if no config is present
# TODO: make formal
# TODO: make formal
data_config
=
{
'
array_format
'
:
None
,
data_config
=
{
'
array_format
'
:
{}
,
'
rotation
'
:
None
,
'
rotation
'
:
None
,
'
camera
'
:
None
,
'
camera
'
:
None
,
'
path
'
:
stream_name
}
'
path
'
:
stream_name
}
...
...
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