Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FruitBin
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guillaume Duret
FruitBin
Commits
42cb938c
Commit
42cb938c
authored
2 years ago
by
Guillaume Duret
Browse files
Options
Downloads
Patches
Plain Diff
optimisation masks
parent
f013a175
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bbox_2d.py
+20
-110
20 additions, 110 deletions
bbox_2d.py
compute_features.py
+36
-20
36 additions, 20 deletions
compute_features.py
instance_mask.py
+10
-13
10 additions, 13 deletions
instance_mask.py
main.py
+3
-3
3 additions, 3 deletions
main.py
with
69 additions
and
146 deletions
bbox_2d.py
+
20
−
110
View file @
42cb938c
...
...
@@ -2,96 +2,6 @@ import math
import
numpy
as
np
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
:
#print('i : ',i)
#print(i['id'])
#print(id_instances)
if
i
[
'
occlusion_value
'
]
>
0.5
:
catergories_occ_array
[
catergories_instance_array_id_to_cat
[
i
[
'
id
'
]]].
append
(
i
[
'
id
'
])
# if i['id'] in id_instances :
# print("Hello banana instance occ")
# if i['occlusion_value'] > 0.5 :
# id_instances_good.append(i['id'])
# print(i['id'])
# print(i['occlusion_value'])
print
(
catergories_occ_array
)
# Closing file
f2
.
close
()
return
catergories_occ_array
def
bbox_2d
(
data_sample
):
center
=
data_sample
[
'
bbox
'
][
'
center
'
]
...
...
@@ -108,34 +18,34 @@ def bbox_2d(data_sample):
return
bbox_res
def
generate_2d_bbox
(
data_name
,
Nb_camera
,
Nb_world
,
list_categories
,
occ_target
):
#
def generate_2d_bbox(data_name, Nb_camera, Nb_world, list_categories, occ_target):
cont1
,
cont2
,
cont3
=
0
,
0
,
0
num_arr
=
0
#
cont1, cont2, cont3 = 0, 0, 0
#
num_arr = 0
for
i
in
range
(
1
,
Nb_world
+
1
):
# worlds
#
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
)
#
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
#
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
)
#
catergories_occ_array = compute_id_good_occ(data_name, p, catergories_instance_array_id_to_cat, catergories_instance_array_cat_to_id, occ_target)
with
open
(
f
"
{
data_name
}
/Bbox_2d/
{
p
}
.json
"
,
'
r
'
)
as
f
:
data
=
json
.
load
(
f
)
#
with open(f"{data_name}/Bbox_2d/{p}.json", 'r') as f:
#
data
_Bbox_2d
= json.load(f)
for
k
in
range
(
len
(
data
)):
#
for k in range(len(data
_Bbox_2d
)):
for
categories
in
list_categories
:
#
for categories in list_categories:
if
len
(
catergories_occ_array
[
categories
])
==
1
and
data
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
cont1
+=
1
bbox
=
bbox_2d
(
data
[
k
])
np
.
savetxt
(
f
'
{
data_name
}
/Generated/Bbox/
{
categories
}
/
{
p
}
.txt
'
,
np
.
array
(
bbox
).
reshape
((
1
,
4
)))
# save
else
:
continue
print
(
cont1
,
cont2
,
cont3
)
#
if len(catergories_occ_array[categories]) == 1 and data
_Bbox_2d
[k]['id'] == catergories_occ_array[categories][0]:
#
cont1 += 1
#
bbox = bbox_2d(data
_Bbox_2d
[k])
#
np.savetxt(f'{data_name}/Generated/Bbox/{categories}/{p}.txt', np.array(bbox).reshape((1, 4))) # save
#
else:
#
continue
#
print(cont1, cont2, cont3)
This diff is collapsed.
Click to expand it.
compute_features.py
+
36
−
20
View file @
42cb938c
...
...
@@ -6,7 +6,7 @@ import numpy as np
import
json
from
utils
import
compute_categories_id
,
compute_id_good_occ
from
scipy.spatial.transform
import
Rotation
from
bbox_2d
import
bbox_2d
def
convert2
(
xyz
):
...
...
@@ -33,31 +33,47 @@ def process_compute(data_name, Nb_camera, Nb_world, list_categories, occ_target)
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 ###
### 3D Poses ###
with
open
(
f
'
{
data_name
}
/Pose/
{
p
}
.json
'
,
'
r
'
)
as
f
:
data
=
json
.
load
(
f
)
data
_3D_pose
=
json
.
load
(
f
)
#print(data)
print
(
"
len(data)
"
,
len
(
data
))
print
(
"
len(data)
"
,
len
(
data_3D_pose
))
### 2D BBox ###
with
open
(
f
"
{
data_name
}
/Bbox_2d/
{
p
}
.json
"
,
'
r
'
)
as
f
:
data_Bbox_2d
=
json
.
load
(
f
)
if
len
(
data_Bbox_2d
)
!=
len
(
data_3D_pose
)
:
raise
TypeError
(
"
size of datas are differents !!
"
)
for
k
in
range
(
len
(
data
)):
for
k
in
range
(
len
(
data
_3D_pose
)):
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
if
len
(
catergories_occ_array
[
categories
])
==
1
:
if
data_3D_pose
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
cont1
+=
1
rpy
=
data_3D_pose
[
k
][
'
pose
'
][
'
rpy
'
]
rot
=
convert2
(
rpy
)
R_exp
=
transformation
@
rot
R_exp
=
np
.
array
(
R_exp
)
xyz
=
data_3D_pose
[
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
if
data_Bbox_2d
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
cont1
+=
1
bbox
=
bbox_2d
(
data_Bbox_2d
[
k
])
np
.
savetxt
(
f
'
{
data_name
}
/Generated/Bbox/
{
categories
}
/
{
p
}
.txt
'
,
np
.
array
(
bbox
).
reshape
((
1
,
4
)))
# save
else
:
continue
print
(
cont1
,
cont2
,
cont3
)
...
...
This diff is collapsed.
Click to expand it.
instance_mask.py
+
10
−
13
View file @
42cb938c
...
...
@@ -113,30 +113,27 @@ def generate_instance_mask(data_name, Nb_camera, Nb_world,list_categories, occ_t
for
j
in
range
(
1
,
Nb_camera
+
1
):
# cameras
k
=
((
i
-
1
)
*
Nb_camera
)
+
j
p
=
((
i
-
1
)
*
Nb_camera
)
+
j
catergories_occ_array
=
compute_id_good_occ
(
data_name
,
k
,
catergories_instance_array_id_to_cat
,
catergories_instance_array_cat_to_id
,
occ_target
)
catergories_occ_array
=
compute_id_good_occ
(
data_name
,
p
,
catergories_instance_array_id_to_cat
,
catergories_instance_array_cat_to_id
,
occ_target
)
for
categories
in
list_categories
:
if
len
(
catergories_occ_array
[
categories
])
==
1
:
id
=
catergories_occ_array
[
categories
][
0
]
print
(
"
iddd :
"
,
id
)
img
=
cv2
.
imread
(
f
"
{
data_name
}
/Instance_Segmentation/
{
p
}
.png
"
,
cv2
.
IMREAD_UNCHANGED
)
# plt.imread(path)
path
=
Path
(
f
"
{
data_name
}
/Instance_Segmentation/
{
k
}
.png
"
)
if
path
.
is_file
():
id
=
catergories_occ_array
[
categories
][
0
]
print
(
"
iddd :
"
,
id
)
img
=
cv2
.
imread
(
f
"
{
data_name
}
/Instance_Segmentation/
{
k
}
.png
"
,
cv2
.
IMREAD_UNCHANGED
)
# plt.imread(path)
#print("img[817][308] : ", img[817][308])
print
(
"
img[308][817] :
"
,
img
[
308
][
817
])
#print("img[817][308] : ", img[817][308])
print
(
"
img[308][817] :
"
,
img
[
308
][
817
])
instance_img
=
instance
(
img
,
id
)
print
(
"
instance_img[308][817] :
"
,
instance_img
[
308
][
817
])
instance_img
=
instance
(
img
,
id
)
print
(
"
instance_img[308][817] :
"
,
instance_img
[
308
][
817
])
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/Instance_Mask/
{
categories
}
/
{
k
}
.png
"
,
255
*
instance_img
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/Instance_Mask/
{
categories
}
/
{
p
}
.png
"
,
255
*
instance_img
)
This diff is collapsed.
Click to expand it.
main.py
+
3
−
3
View file @
42cb938c
...
...
@@ -2,8 +2,8 @@ import os
import
numpy
as
np
import
json
from
prepare_data
import
reform_data
from
pose
import
transform_pose
from
bbox_2d
import
generate_2d_bbox
#
from pose import transform_pose
#
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
...
...
@@ -65,7 +65,7 @@ if __name__ == '__main__':
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_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
)
#generate_3d_bbox(dataset_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