Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cocoapi
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
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
National Facility
cocoapi
Commits
97b1791a
Commit
97b1791a
authored
7 years ago
by
Yasser Souri
Browse files
Options
Downloads
Patches
Plain Diff
add and use _isArrayLike in PythonAPI
now it is possible to pass sets or numpy arrays to functions like `loadImgs`
parent
336d2a27
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
PythonAPI/pycocotools/coco.py
+18
-10
18 additions, 10 deletions
PythonAPI/pycocotools/coco.py
with
18 additions
and
10 deletions
PythonAPI/pycocotools/coco.py
+
18
−
10
View file @
97b1791a
...
...
@@ -62,6 +62,14 @@ if PYTHON_VERSION == 2:
elif
PYTHON_VERSION
==
3
:
from
urllib.request
import
urlretrieve
def
_isArrayLike
(
obj
):
if
hasattr
(
obj
,
'
__iter__
'
)
and
hasattr
(
obj
,
'
__len__
'
):
return
True
else
:
return
False
class
COCO
:
def
__init__
(
self
,
annotation_file
=
None
):
"""
...
...
@@ -130,8 +138,8 @@ class COCO:
iscrowd (boolean) : get anns for given crowd label (False or True)
:return: ids (int array) : integer array of ann ids
"""
imgIds
=
imgIds
if
typ
e
(
imgIds
)
==
list
else
[
imgIds
]
catIds
=
catIds
if
typ
e
(
catIds
)
==
list
else
[
catIds
]
imgIds
=
imgIds
if
_isArrayLik
e
(
imgIds
)
else
[
imgIds
]
catIds
=
catIds
if
_isArrayLik
e
(
catIds
)
else
[
catIds
]
if
len
(
imgIds
)
==
len
(
catIds
)
==
len
(
areaRng
)
==
0
:
anns
=
self
.
dataset
[
'
annotations
'
]
...
...
@@ -157,9 +165,9 @@ class COCO:
:param catIds (int array) : get cats for given cat ids
:return: ids (int array) : integer array of cat ids
"""
catNms
=
catNms
if
typ
e
(
catNms
)
==
list
else
[
catNms
]
supNms
=
supNms
if
typ
e
(
supNms
)
==
list
else
[
supNms
]
catIds
=
catIds
if
typ
e
(
catIds
)
==
list
else
[
catIds
]
catNms
=
catNms
if
_isArrayLik
e
(
catNms
)
else
[
catNms
]
supNms
=
supNms
if
_isArrayLik
e
(
supNms
)
else
[
supNms
]
catIds
=
catIds
if
_isArrayLik
e
(
catIds
)
else
[
catIds
]
if
len
(
catNms
)
==
len
(
supNms
)
==
len
(
catIds
)
==
0
:
cats
=
self
.
dataset
[
'
categories
'
]
...
...
@@ -178,8 +186,8 @@ class COCO:
:param catIds (int array) : get imgs with all given cats
:return: ids (int array) : integer array of img ids
'''
imgIds
=
imgIds
if
typ
e
(
imgIds
)
==
list
else
[
imgIds
]
catIds
=
catIds
if
typ
e
(
catIds
)
==
list
else
[
catIds
]
imgIds
=
imgIds
if
_isArrayLik
e
(
imgIds
)
else
[
imgIds
]
catIds
=
catIds
if
_isArrayLik
e
(
catIds
)
else
[
catIds
]
if
len
(
imgIds
)
==
len
(
catIds
)
==
0
:
ids
=
self
.
imgs
.
keys
()
...
...
@@ -198,7 +206,7 @@ class COCO:
:param ids (int array) : integer ids specifying anns
:return: anns (object array) : loaded ann objects
"""
if
type
(
ids
)
==
list
:
if
_isArrayLike
(
ids
)
:
return
[
self
.
anns
[
id
]
for
id
in
ids
]
elif
type
(
ids
)
==
int
:
return
[
self
.
anns
[
ids
]]
...
...
@@ -209,7 +217,7 @@ class COCO:
:param ids (int array) : integer ids specifying cats
:return: cats (object array) : loaded cat objects
"""
if
type
(
ids
)
==
list
:
if
_isArrayLike
(
ids
)
:
return
[
self
.
cats
[
id
]
for
id
in
ids
]
elif
type
(
ids
)
==
int
:
return
[
self
.
cats
[
ids
]]
...
...
@@ -220,7 +228,7 @@ class COCO:
:param ids (int array) : integer ids specifying img
:return: imgs (object array) : loaded img objects
"""
if
type
(
ids
)
==
list
:
if
_isArrayLike
(
ids
)
:
return
[
self
.
imgs
[
id
]
for
id
in
ids
]
elif
type
(
ids
)
==
int
:
return
[
self
.
imgs
[
ids
]]
...
...
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