Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lucas Miranda
deepOF
Commits
8fbfe342
Commit
8fbfe342
authored
Sep 30, 2020
by
lucas_miranda
Browse files
Fixed bug in file name recognition in data.py
parent
be362675
Changes
3
Hide whitespace changes
Inline
Side-by-side
deepof/data.py
View file @
8fbfe342
...
...
@@ -21,6 +21,7 @@ from sklearn import random_projection
from
sklearn.decomposition
import
KernelPCA
from
sklearn.manifold
import
TSNE
from
sklearn.preprocessing
import
MinMaxScaler
,
StandardScaler
from
tqdm
import
tqdm
import
deepof.pose_utils
import
deepof.utils
import
deepof.visuals
...
...
@@ -95,11 +96,11 @@ class project:
def
__str__
(
self
):
if
self
.
exp_conditions
:
return
"
DLC
analysis of {} videos across {} conditions"
.
format
(
return
"
deepof
analysis of {} videos across {} conditions"
.
format
(
len
(
self
.
videos
),
len
(
self
.
exp_conditions
)
)
else
:
return
"
DLC
analysis of {} videos"
.
format
(
len
(
self
.
videos
))
return
"
deepof
analysis of {} videos"
.
format
(
len
(
self
.
videos
))
@
property
def
subset_condition
(
self
):
...
...
@@ -167,7 +168,7 @@ class project:
if
self
.
table_format
==
".h5"
:
tab_dict
=
{
deepof
.
utils
.
re
.
findall
(
"(.*
?)_
"
,
tab
)[
0
]:
pd
.
read_hdf
(
deepof
.
utils
.
re
.
findall
(
"(.*
)DLC
"
,
tab
)[
0
]:
pd
.
read_hdf
(
deepof
.
utils
.
os
.
path
.
join
(
self
.
table_path
,
tab
),
dtype
=
float
)
for
tab
in
self
.
tables
...
...
@@ -192,7 +193,7 @@ class project:
],
names
=
[
"scorer"
,
"bodyparts"
,
"coords"
],
)
tab_dict
[
deepof
.
utils
.
re
.
findall
(
"(.*
?)_
"
,
tab
)[
0
]]
=
data
tab_dict
[
deepof
.
utils
.
re
.
findall
(
"(.*
)DLC
"
,
tab
)[
0
]]
=
data
lik_dict
=
defaultdict
()
...
...
@@ -409,7 +410,7 @@ class coordinates:
len
(
self
.
_videos
),
len
(
self
.
_exp_conditions
)
)
else
:
return
"
DLC
analysis of {} videos"
.
format
(
len
(
self
.
_videos
))
return
"
deepof
analysis of {} videos"
.
format
(
len
(
self
.
_videos
))
def
get_coords
(
self
,
...
...
@@ -643,12 +644,13 @@ class coordinates:
"""Annotates coordinates using a simple rule-based pipeline"""
tag_dict
=
{}
for
idx
,
key
in
enumerate
(
self
.
_tables
.
keys
()):
for
idx
,
key
in
tqdm
(
enumerate
(
self
.
_tables
.
keys
())
,
total
=
len
(
self
.
_videos
))
:
tag_dict
[
key
]
=
deepof
.
pose_utils
.
rule_based_tagging
(
list
(
self
.
_tables
.
keys
()),
self
.
_videos
,
self
,
idx
,
arena_type
=
self
.
_arena
,
recog_limit
=
1
,
path
=
os
.
path
.
join
(
self
.
_path
,
"Videos"
),
hparams
=
hparams
,
...
...
@@ -972,7 +974,6 @@ def merge_tables(*args):
# TODO:
# - Generate ragged training array using a metric (acceleration, maybe?)
# - Use something like Dynamic Time Warping to put all instances in the same length
# - add rule_based_annotation method to coordinates class!!
# - with the current implementation, preprocess can't fully work on merged table_dict instances.
# While some operations (mainly alignment) should be carried out before merging, others require
# the whole dataset to function properly.
deepof/pose_utils.py
View file @
8fbfe342
...
...
@@ -17,7 +17,6 @@ import pandas as pd
import
regex
as
re
import
seaborn
as
sns
from
itertools
import
combinations
from
scipy
import
spatial
from
scipy
import
stats
from
tqdm
import
tqdm
from
typing
import
Any
,
List
,
NewType
...
...
@@ -110,7 +109,12 @@ def close_double_contact(
def
climb_wall
(
arena_type
:
str
,
arena
:
np
.
array
,
pos_dict
:
pd
.
DataFrame
,
tol
:
float
,
nose
:
str
arena_type
:
str
,
arena
:
np
.
array
,
pos_dict
:
pd
.
DataFrame
,
tol
:
float
,
nose
:
str
,
centered_data
:
bool
=
True
,
)
->
np
.
array
:
"""Returns True if the specified mouse is climbing the wall
...
...
@@ -129,7 +133,7 @@ def climb_wall(
nose
=
pos_dict
[
nose
]
if
arena_type
==
"circular"
:
center
=
np
.
array
(
arena
[:
2
])
center
=
np
.
zeros
(
2
)
if
centered_data
else
np
.
array
(
arena
[:
2
])
climbing
=
np
.
linalg
.
norm
(
nose
-
center
,
axis
=
1
)
>
(
arena
[
2
]
+
tol
)
else
:
...
...
@@ -420,6 +424,7 @@ def rule_based_tagging(
videos
:
List
,
coordinates
:
Coordinates
,
vid_index
:
int
,
arena_type
:
str
,
recog_limit
:
int
=
1
,
path
:
str
=
os
.
path
.
join
(
"."
),
hparams
:
dict
=
{},
...
...
@@ -455,7 +460,7 @@ def rule_based_tagging(
undercond
=
"_"
if
len
(
animal_ids
)
>
1
else
""
try
:
vid_name
=
re
.
findall
(
"(.*
?)_
"
,
tracks
[
vid_index
])[
0
]
vid_name
=
re
.
findall
(
"(.*
)DLC
"
,
tracks
[
vid_index
])[
0
]
except
IndexError
:
vid_name
=
tracks
[
vid_index
]
...
...
@@ -527,15 +532,7 @@ def rule_based_tagging(
for
_id
in
animal_ids
:
tag_dict
[
_id
+
undercond
+
"climbing"
]
=
deepof
.
utils
.
smooth_boolean_array
(
pd
.
Series
(
(
spatial
.
distance
.
cdist
(
np
.
array
(
coords
[
_id
+
undercond
+
"Nose"
]),
np
.
zeros
([
1
,
2
])
)
>
(
w
/
200
+
arena
[
2
])
).
reshape
(
coords
.
shape
[
0
]),
index
=
coords
.
index
,
).
astype
(
bool
)
climb_wall
(
arena_type
,
arena
,
coords
,
w
/
200
,
_id
+
undercond
+
"Nose"
)
)
tag_dict
[
_id
+
undercond
+
"speed"
]
=
speeds
[
_id
+
undercond
+
"Center"
]
tag_dict
[
_id
+
undercond
+
"huddle"
]
=
deepof
.
utils
.
smooth_boolean_array
(
...
...
@@ -695,7 +692,7 @@ def rule_based_video(
undercond
=
"_"
if
len
(
animal_ids
)
>
1
else
""
try
:
vid_name
=
re
.
findall
(
"(.*
?)_
"
,
tracks
[
vid_index
])[
0
]
vid_name
=
re
.
findall
(
"(.*
)DLC
"
,
tracks
[
vid_index
])[
0
]
except
IndexError
:
vid_name
=
tracks
[
vid_index
]
...
...
tests/test_pose_utils.py
View file @
8fbfe342
...
...
@@ -366,6 +366,7 @@ def test_rule_based_tagging():
list
([
i
+
"_"
for
i
in
prun
.
get_coords
().
keys
()]),
[
"test_video_circular_arena.mp4"
],
prun
,
arena_type
=
"circular"
,
vid_index
=
0
,
path
=
os
.
path
.
join
(
"."
,
"tests"
,
"test_examples"
,
"Videos"
),
)
...
...
@@ -389,6 +390,7 @@ def test_rule_based_video():
list
([
i
+
"_"
for
i
in
prun
.
get_coords
().
keys
()]),
[
"test_video_circular_arena.mp4"
],
prun
,
arena_type
=
"circular"
,
vid_index
=
0
,
path
=
os
.
path
.
join
(
"."
,
"tests"
,
"test_examples"
,
"Videos"
),
)
...
...
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