Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pvnet_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
Pvnet_FruitBIn
Commits
b0129f48
Commit
b0129f48
authored
2 years ago
by
maali
Browse files
Options
Downloads
Patches
Plain Diff
Update the paths in the data part
parent
cb919de9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
data.py
+35
-22
35 additions, 22 deletions
data.py
with
35 additions
and
22 deletions
data.py
+
35
−
22
View file @
b0129f48
...
...
@@ -73,11 +73,16 @@ def getMasterList_Fruits(basePath): # returns list with image, mask, and label
return
[[
a
,
b
,
c
]
for
a
,
b
,
c
in
zip
(
imageList
,
maskList
,
labelList
)]
def
classTrainingGenerator
(
model
,
batchSize
,
masterList
=
None
,
height
=
480
,
width
=
640
,
augmentation
=
True
,
def
classTrainingGenerator
(
model
,
batchSize
,
masterList
=
None
,
height
=
480
,
width
=
640
,
augmentation
=
True
,
val
=
False
,
**
unused
):
# take input image, resize and store as rgb, create mask training data
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/LINEMOD/
'
+
model
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/Generated_Worlds_/Generated_Worlds_Training/
'
+
model
if
val
:
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/Generated_Worlds_/Generated_Worlds_Evaluating/
'
+
model
if
masterList
is
None
:
masterList
=
getMasterList
(
basePath
)
masterList
=
getMasterList
_Fruits
(
basePath
)
random
.
shuffle
(
masterList
)
i
=
0
while
True
:
...
...
@@ -87,10 +92,10 @@ def classTrainingGenerator(model, batchSize, masterList=None, height=480, width=
if
i
==
len
(
masterList
):
i
=
0
random
.
shuffle
(
masterList
)
x
=
filePathToArray
(
basePath
+
'
/
rgb
/
'
+
masterList
[
i
][
0
],
height
,
width
)
x
=
filePathToArray
(
basePath
+
'
/
RGB_resized
/
'
+
masterList
[
i
][
0
],
height
,
width
)
yClassLabels
=
np
.
zeros
((
height
,
width
,
1
))
# 1 class confidence value per model
modelMask
=
filePathToArray
(
basePath
+
'
/
mask
/
'
+
masterList
[
i
][
1
],
height
,
width
)
modelMask
=
filePathToArray
(
basePath
+
'
/
Instance_Mask_resized
/
'
+
masterList
[
i
][
1
],
height
,
width
)
if
augmentation
:
if
random
.
choice
([
True
,
False
]):
# vertical flip
...
...
@@ -112,13 +117,17 @@ def classTrainingGenerator(model, batchSize, masterList=None, height=480, width=
yield
np
.
array
(
xBatch
),
np
.
array
(
yClassBatch
)
def
coordsTrainingGenerator
(
model
,
batchSize
,
masterList
=
None
,
height
=
480
,
width
=
640
,
augmentation
=
True
,
def
coordsTrainingGenerator
(
model
,
batchSize
,
masterList
=
None
,
val
=
False
,
height
=
480
,
width
=
640
,
augmentation
=
True
,
altLabels
=
True
):
# takes input image and generates unit vector training data
print
(
f
"
--------
{
batchSize
}
----------
"
)
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/LINEMOD/
'
+
model
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/Generated_Worlds_/Generated_Worlds_Training/
'
+
model
if
val
:
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/Generated_Worlds_/Generated_Worlds_Evaluating/
'
+
model
if
masterList
==
None
:
masterList
=
getMasterList
(
basePath
)
masterList
=
getMasterList
_Fruits
(
basePath
)
random
.
shuffle
(
masterList
)
i
=
0
while
True
:
...
...
@@ -128,14 +137,14 @@ def coordsTrainingGenerator(model, batchSize, masterList=None, height=480, width
if
i
==
len
(
masterList
):
i
=
0
random
.
shuffle
(
masterList
)
x
=
filePathToArray
(
basePath
+
'
/
rgb
/
'
+
masterList
[
i
][
0
],
height
,
width
)
x
=
filePathToArray
(
basePath
+
'
/
RGB_resized
/
'
+
masterList
[
i
][
0
],
height
,
width
)
with
open
(
basePath
+
(
'
/altLabels/
'
if
altLabels
else
'
/
labels
/
'
)
+
masterList
[
i
][
2
])
as
f
:
with
open
(
basePath
+
(
'
/altLabels/
'
if
altLabels
else
'
/
FPS_resized
/
'
)
+
masterList
[
i
][
2
])
as
f
:
labels
=
f
.
readline
().
split
(
'
'
)[
1
:
19
]
yCoordsLabels
=
np
.
zeros
((
height
,
width
,
18
))
# 9 coordinates
modelMask
=
filePathToArray
(
basePath
+
'
/
mask
/
'
+
masterList
[
i
][
1
],
height
,
width
)
modelMask
=
filePathToArray
(
basePath
+
'
/
Instance_Mask_resized
/
'
+
masterList
[
i
][
1
],
height
,
width
)
if
augmentation
:
if
random
.
choice
([
True
,
False
]):
# vertical flip
...
...
@@ -158,12 +167,16 @@ def coordsTrainingGenerator(model, batchSize, masterList=None, height=480, width
yield
np
.
array
(
xBatch
),
np
.
array
(
yCoordBatch
)
def
combinedTrainingGenerator
(
model
,
batchSize
,
masterList
=
None
,
height
=
480
,
width
=
640
,
out0
=
'
activation_9
'
,
def
combinedTrainingGenerator
(
model
,
batchSize
,
masterList
=
None
,
val
=
False
,
height
=
480
,
width
=
640
,
out0
=
'
activation_9
'
,
out1
=
'
activation_10
'
,
augmentation
=
True
,
altLabels
=
True
):
# take input image, resize and store as rgb, create training data
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/LINEMOD/
'
+
model
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/Generated_Worlds_/Generated_Worlds_Training/
'
+
model
if
val
:
basePath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
+
'
/Generated_Worlds_/Generated_Worlds_Evaluating/
'
+
model
if
masterList
is
None
:
masterList
=
getMasterList
(
basePath
)
masterList
=
getMasterList
_Fruits
(
basePath
)
i
=
0
while
True
:
xBatch
=
[]
...
...
@@ -173,16 +186,16 @@ def combinedTrainingGenerator(model, batchSize, masterList=None, height=480, wid
if
i
==
len
(
masterList
):
i
=
0
random
.
shuffle
(
masterList
)
x
=
filePathToArray
(
basePath
+
'
/
rgb
/
'
+
masterList
[
i
][
0
],
height
,
width
)
x
=
filePathToArray
(
basePath
+
'
/
RGB_resized
/
'
+
masterList
[
i
][
0
],
height
,
width
)
with
open
(
basePath
+
(
'
/altLabels/
'
if
altLabels
else
'
/
labels
/
'
)
+
masterList
[
i
][
2
])
as
f
:
with
open
(
basePath
+
(
'
/altLabels/
'
if
altLabels
else
'
/
FPS_resized
/
'
)
+
masterList
[
i
][
2
])
as
f
:
labels
=
f
.
readline
().
split
(
'
'
)[
1
:
19
]
yCoordsLabels
=
np
.
zeros
((
height
,
width
,
18
))
# 9 coordinates
yClassLabels
=
np
.
zeros
((
height
,
width
,
1
))
# 1 class confidence value per model
# yClassLabels = np.tile(np.array([1, 0]),(height, width, 1))
modelMask
=
filePathToArray
(
basePath
+
'
/
mask
/
'
+
masterList
[
i
][
1
],
height
,
width
)
modelMask
=
filePathToArray
(
basePath
+
'
/
Instance_Mask_resized
/
'
+
masterList
[
i
][
1
],
height
,
width
)
if
augmentation
:
# for data aug, get random horizontal, vertical flips, flip input x with np, label vals = 1 - labelvals, flip mask
...
...
@@ -293,17 +306,18 @@ def getDataSplit(genNew=False, split=.8, modelClass='cat'):
splitDict
=
pickle
.
load
(
f
)
return
splitDict
[
"
trainData
"
],
splitDict
[
"
validData
"
]
def
getDataSplit_Fruits
(
genNew
=
False
,
split
=
.
8
,
modelClass
=
'
cat
'
):
def
getDataSplit_Fruits
(
genNew
=
True
,
split
=
.
8
,
modelClass
=
'
cat
'
):
# access training data, get jpeg, mask, label filenames split into training / validation sets
if
genNew
:
# create split
basePathTraining
=
f
'
/home/
gduret/Documents/guimod
/Generated_Worlds_Training/
{
modelClass
}
'
# os.path.dirname(os.path.realpath(__file__)) + '/LINEMOD/' + modelClass
basePathEvaluating
=
f
'
/home/
gduret/Documents/guimod
/Generated_Worlds_Evaluating/
{
modelClass
}
'
basePathTraining
=
f
'
/home/
mahmoud/pvnet_method/Generated_Worlds_
/Generated_Worlds_Training/
{
modelClass
}
'
# os.path.dirname(os.path.realpath(__file__)) + '/LINEMOD/' + modelClass
basePathEvaluating
=
f
'
/home/
mahmoud/pvnet_method/Generated_Worlds_
/Generated_Worlds_Evaluating/
{
modelClass
}
'
masterList_Training
=
getMasterList_Fruits
(
basePathTraining
)
masterList_Evalution
=
getMasterList_Fruits
(
basePathEvaluating
)
random
.
shuffle
(
masterList_Training
)
random
.
shuffle
(
masterList_Evalution
)
#splitPoint = round(len(masterList) * split)
#
splitPoint = round(len(masterList) * split)
splitDict
=
{
"
trainData
"
:
masterList_Training
,
"
validData
"
:
masterList_Evalution
}
...
...
@@ -316,7 +330,6 @@ def getDataSplit_Fruits(genNew=False, split=.8, modelClass='cat'):
return
splitDict
[
"
trainData
"
],
splitDict
[
"
validData
"
]
def
genAltLabels
(
p3dOld
,
p3dNew
,
matrix
=
np
.
array
([[
572.4114
,
0.
,
325.2611
],
[
0.
,
573.57043
,
242.04899
],
[
0.
,
0.
,
1.
]]),
method
=
cv2
.
SOLVEPNP_ITERATIVE
,
modelClass
=
'
cat
'
,
height
=
480
,
width
=
640
,
showPoint
=
False
):
# generate pixel labels for p3dNew using labels for p3dOld
...
...
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