Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FruitBin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
Guillaume Duret
FruitBin
Commits
f013a175
Commit
f013a175
authored
Feb 24, 2023
by
Guillaume Duret
Browse files
Options
Downloads
Patches
Plain Diff
prepare optimization
parent
a1be92c1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
compute_features.py
+64
-0
64 additions, 0 deletions
compute_features.py
main.py
+3
-1
3 additions, 1 deletion
main.py
utils.py
+69
-0
69 additions, 0 deletions
utils.py
with
136 additions
and
1 deletion
compute_features.py
0 → 100644
+
64
−
0
View file @
f013a175
import
math
import
numpy
as
np
import
json
from
utils
import
compute_categories_id
,
compute_id_good_occ
from
scipy.spatial.transform
import
Rotation
def
convert2
(
xyz
):
(
R
,
P
,
Y
)
=
(
xyz
[
0
],
xyz
[
1
],
xyz
[
2
])
Q
=
Rotation
.
from_euler
(
seq
=
'
xyz
'
,
angles
=
[
R
,
P
,
Y
],
degrees
=
False
).
as_quat
()
r
=
Rotation
.
from_quat
(
Q
)
rotation
=
r
.
as_matrix
()
return
rotation
def
process_compute
(
data_name
,
Nb_camera
,
Nb_world
,
list_categories
,
occ_target
):
transformation
=
np
.
matrix
([[
0.0000000
,
-
1.0000000
,
0.0000000
],
[
0.0000000
,
0.0000000
,
-
1.0000000
],
[
1.0000000
,
0.0000000
,
0.0000000
]])
cont1
,
cont2
,
cont3
=
0
,
0
,
0
for
i
in
range
(
1
,
Nb_world
+
1
):
# worlds
catergories_instance_array_id_to_cat
,
catergories_instance_array_cat_to_id
=
compute_categories_id
(
data_name
,
i
)
for
j
in
range
(
1
,
Nb_camera
+
1
):
# cameras
p
=
((
i
-
1
)
*
Nb_camera
)
+
j
catergories_occ_array
=
compute_id_good_occ
(
data_name
,
p
,
catergories_instance_array_id_to_cat
,
catergories_instance_array_cat_to_id
,
occ_target
)
### Generate Poses ###
with
open
(
f
'
{
data_name
}
/Pose/
{
p
}
.json
'
,
'
r
'
)
as
f
:
data
=
json
.
load
(
f
)
#print(data)
print
(
"
len(data)
"
,
len
(
data
))
for
k
in
range
(
len
(
data
)):
for
categories
in
list_categories
:
if
len
(
catergories_occ_array
[
categories
])
==
1
and
data
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
cont1
+=
1
rpy
=
data
[
k
][
'
pose
'
][
'
rpy
'
]
rot
=
convert2
(
rpy
)
R_exp
=
transformation
@
rot
R_exp
=
np
.
array
(
R_exp
)
xyz
=
data
[
k
][
'
pose
'
][
'
xyz
'
]
T_exp
=
transformation
@
xyz
T_exp
=
np
.
array
(
T_exp
)
num_arr
=
np
.
c_
[
R_exp
,
T_exp
[
0
]]
np
.
save
(
f
'
{
data_name
}
/Generated/Pose_transformed/
{
categories
}
/
{
p
}
.npy
'
,
num_arr
)
# save
else
:
continue
print
(
cont1
,
cont2
,
cont3
)
This diff is collapsed.
Click to expand it.
main.py
+
3
−
1
View file @
f013a175
...
...
@@ -7,6 +7,7 @@ from bbox_2d import generate_2d_bbox
from
instance_mask
import
generate_instance_mask
from
fps_alg
import
generate_fps
from
bbox_3d
import
generate_3d_bbox
from
compute_features
import
process_compute
import
shutil
...
...
@@ -62,7 +63,8 @@ if __name__ == '__main__':
reform_data
(
dataset_src
,
dataset_name
,
dataset_type
,
frame
,
Nb_camera
,
Nb_world
)
transform_pose
(
dataset_name
,
Nb_camera
,
Nb_world
,
list_categories
,
occ_target
)
process_compute
(
dataset_name
,
Nb_camera
,
Nb_world
,
list_categories
,
occ_target
)
#transform_pose(dataset_name, Nb_camera, Nb_world, list_categories, occ_target)
generate_2d_bbox
(
dataset_name
,
Nb_camera
,
Nb_world
,
list_categories
,
occ_target
)
generate_instance_mask
(
dataset_name
,
Nb_camera
,
Nb_world
,
list_categories
,
occ_target
)
generate_fps
(
dataset_name
,
camera
,
Nb_camera
,
Nb_world
,
list_categories
,
True
)
...
...
This diff is collapsed.
Click to expand it.
utils.py
0 → 100644
+
69
−
0
View file @
f013a175
import
json
def
compute_categories_id
(
data_name
,
world
):
#Category = 'banana1'
#Category = 'pear2'
#Category = "orange2"
# Opening JSON file
f
=
open
(
f
'
{
data_name
}
/Meta/
{
world
}
.json
'
)
# returns JSON object as
# a dictionary
data
=
json
.
load
(
f
)
# Iterating through the json
# list
catergories_label_to_id
=
{}
catergories_id_to_label
=
{}
catergories_instance_array_cat_to_id
=
{}
catergories_instance_array_id_to_cat
=
{}
for
k
in
data
[
'
categories
'
]:
catergories_label_to_id
[
k
[
'
label
'
]]
=
k
[
'
id
'
]
catergories_id_to_label
[
k
[
'
id
'
]]
=
k
[
'
label
'
]
catergories_instance_array_cat_to_id
[
k
[
'
label
'
]]
=
[]
for
k
in
data
[
'
objects
'
]:
#print(k)
#catergories_instance_array[catergories_id_to_label[i['category_id']]]
catergories_instance_array_id_to_cat
[
k
[
'
id
'
]]
=
catergories_id_to_label
[
k
[
'
category_id
'
]]
catergories_instance_array_cat_to_id
[
catergories_id_to_label
[
k
[
'
category_id
'
]]].
append
(
k
[
'
id
'
])
# if i['category_id'] == id_category :
# print("Hello fruits instance")
# id_instances.append(i['id'])
# print(i['id'])
print
(
"
catergories_instance_array_cat_to_id :
"
,
catergories_instance_array_cat_to_id
)
print
(
"
catergories_instance_array_id_to_cat :
"
,
catergories_instance_array_id_to_cat
)
# Closing file
f
.
close
()
return
catergories_instance_array_id_to_cat
,
catergories_instance_array_cat_to_id
def
compute_id_good_occ
(
data_name
,
count
,
catergories_instance_array_id_to_cat
,
catergories_instance_array_cat_to_id
,
Occ_wanted
):
f2
=
open
(
f
'
{
data_name
}
/Occlusion/
{
count
}
.json
'
)
data2
=
json
.
load
(
f2
)
catergories_occ_array
=
{}
for
cat
in
catergories_instance_array_cat_to_id
:
#print(cat)
catergories_occ_array
[
cat
]
=
[]
for
i
in
data2
:
if
i
[
'
occlusion_value
'
]
>
0.5
:
catergories_occ_array
[
catergories_instance_array_id_to_cat
[
i
[
'
id
'
]]].
append
(
i
[
'
id
'
])
print
(
catergories_occ_array
)
# Closing file
f2
.
close
()
return
catergories_occ_array
\ No newline at end of file
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
sign in
to comment