Upload 7 files
Browse filesWebots files added
- controllers/.DS_Store +0 -0
- controllers/datacollector/.DS_Store +0 -0
- controllers/datacollector/datacollector.py +121 -0
- datasetbuilder.py +33 -0
- worlds/.webots_grasp.jpg +3 -0
- worlds/.webots_grasp.wbproj +11 -0
- worlds/webots_grasp.wbt +0 -0
controllers/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
controllers/datacollector/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
controllers/datacollector/datacollector.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""datacollector controller."""
|
2 |
+
|
3 |
+
# You may need to import some classes of the controller module. Ex:
|
4 |
+
# from controller import Robot, Motor, DistanceSensor
|
5 |
+
from controller import Supervisor
|
6 |
+
import uuid
|
7 |
+
import numpy as np
|
8 |
+
import os
|
9 |
+
|
10 |
+
|
11 |
+
# create the Robot instance.
|
12 |
+
robot = Supervisor()
|
13 |
+
|
14 |
+
# get the time step of the current world.
|
15 |
+
timestep = int(robot.getBasicTimeStep())
|
16 |
+
|
17 |
+
# You should insert a getDevice-like function in order to get the
|
18 |
+
# instance of a device of the robot. Something like:
|
19 |
+
# motor = robot.getDevice('motorname')
|
20 |
+
# ds = robot.getDevice('dsname')
|
21 |
+
# ds.enable(timestep)
|
22 |
+
|
23 |
+
|
24 |
+
rf = robot.getDevice("realsenseD405")
|
25 |
+
camera = robot.getDevice("camera")
|
26 |
+
|
27 |
+
gripper = robot.getDevice("ROBOTIQ 2F-140 Gripper::left finger joint")
|
28 |
+
|
29 |
+
#= {'left' : robot.getDevice("ROBOTIQ 2F-140 Gripper::left finger joint"),
|
30 |
+
# 'right': robot.getDevice("ROBOTIQ 2F-140 Gripper::right finger joint")}
|
31 |
+
|
32 |
+
gripper.setPosition(float('inf'))
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
camera.enable(32)
|
37 |
+
camera.recognitionEnable(32)
|
38 |
+
camera.enableRecognitionSegmentation()
|
39 |
+
rf.enable(32)
|
40 |
+
|
41 |
+
settle_time = 90
|
42 |
+
elapsed_time = 0
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
# Randomize all the nodes that start with "random_"
|
48 |
+
rootNode = robot.getRoot()
|
49 |
+
rootChildren = rootNode.getField("children")
|
50 |
+
n = rootChildren.getCount()
|
51 |
+
print(n," nodes")
|
52 |
+
|
53 |
+
for i in range(n):
|
54 |
+
node = rootChildren.getMFNode(i)
|
55 |
+
if node.getType()==80: # only for solids
|
56 |
+
name=node.getField("name").getSFString()
|
57 |
+
if name.startswith("random"):
|
58 |
+
v=np.random.rand(3)
|
59 |
+
v = v / np.linalg.norm(v) # create unit vector
|
60 |
+
v=[*v,np.random.uniform(-np.pi,+np.pi)] # add random orientation
|
61 |
+
node.getField("rotation").setSFRotation(v)
|
62 |
+
|
63 |
+
|
64 |
+
# Create paths if they don't exist
|
65 |
+
|
66 |
+
path = "../../data/"
|
67 |
+
directories = ['d','rgb','mask','meta']
|
68 |
+
for directory in directories:
|
69 |
+
directory=path+directory
|
70 |
+
if not os.path.exists(directory):
|
71 |
+
os.makedirs(directory)
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
# Main loop:
|
76 |
+
# - perform simulation steps until Webots is stopping the controller
|
77 |
+
while robot.step(timestep) != -1:
|
78 |
+
gripper.setVelocity(-0.3) # keep gripper open
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
if(elapsed_time>=settle_time):
|
83 |
+
fname = str(uuid.uuid4())
|
84 |
+
#fname =""
|
85 |
+
|
86 |
+
rf.saveImage(path + 'd/'+ fname + "_depth.png",quality=100)
|
87 |
+
camera.saveImage(path + 'rgb/' + fname + "_rgb.png",quality=100)
|
88 |
+
camera.saveRecognitionSegmentationImage(path + 'mask/' + fname + "_mask.png",quality=100)
|
89 |
+
objects=camera.getRecognitionObjects()
|
90 |
+
|
91 |
+
metadata=[]
|
92 |
+
for object in objects:
|
93 |
+
|
94 |
+
info = {'id': object.getId(),
|
95 |
+
'file' : fname,
|
96 |
+
'position' : np.array(object.getPosition()).tolist(),
|
97 |
+
'orientation' : np.array(object.getOrientation()).tolist(),
|
98 |
+
'size' : np.array(object.getSize()).tolist(),
|
99 |
+
'positionOnImage' : np.array(object.getPositionOnImage()).tolist(),
|
100 |
+
'sizeOnImage' : np.array(object.getSizeOnImage()).tolist(),
|
101 |
+
'numberOfColors' : object.getNumberOfColors(),
|
102 |
+
'colors' : np.ctypeslib.as_array(object.getColors(),(3,)).tolist(),
|
103 |
+
'model' : object.getModel()}
|
104 |
+
metadata.append(info)
|
105 |
+
|
106 |
+
print(metadata)
|
107 |
+
|
108 |
+
import json
|
109 |
+
|
110 |
+
with open(path + 'meta/' +fname+'_meta.json', 'w') as fp:
|
111 |
+
json.dump(metadata, fp)
|
112 |
+
|
113 |
+
robot.getSelf().restartController()
|
114 |
+
robot.simulationResetPhysics()
|
115 |
+
robot.simulationReset()
|
116 |
+
# robot.worldReload()
|
117 |
+
|
118 |
+
elapsed_time+=1
|
119 |
+
pass
|
120 |
+
|
121 |
+
# Enter here exit cleanup code.
|
datasetbuilder.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from os import listdir
|
2 |
+
from datasets import Dataset, Image
|
3 |
+
import json
|
4 |
+
import huggingface_hub
|
5 |
+
|
6 |
+
huggingface_hub.login('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')
|
7 |
+
|
8 |
+
all_rgb=listdir('data/rgb')
|
9 |
+
all_rgb=['data/rgb/' + f for f in all_rgb]
|
10 |
+
|
11 |
+
all_d=listdir('data/d')
|
12 |
+
all_d=['data/d/' + f for f in all_d]
|
13 |
+
|
14 |
+
all_mask=listdir('data/mask')
|
15 |
+
all_mask=['data/mask/' + f for f in all_mask]
|
16 |
+
|
17 |
+
|
18 |
+
all_json =listdir('data/meta')
|
19 |
+
all_jsons=[]
|
20 |
+
|
21 |
+
for jsonfilename in all_json:
|
22 |
+
with open('data/meta/'+jsonfilename) as json_file:
|
23 |
+
data = json.load(json_file)
|
24 |
+
all_jsons.append(data)
|
25 |
+
|
26 |
+
|
27 |
+
ds=Dataset.from_dict({'rgb' : all_rgb,
|
28 |
+
'depth' : all_d,
|
29 |
+
'mask' : all_mask,
|
30 |
+
'meta' : all_jsons}
|
31 |
+
).cast_column('rgb',Image()).cast_column('depth',Image()).cast_column('mask',Image())
|
32 |
+
|
33 |
+
ds.push_to_hub('correll/semanticsegmentationandposeestimationfromrgbd')
|
worlds/.webots_grasp.jpg
ADDED
Git LFS Details
|
worlds/.webots_grasp.wbproj
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Webots Project File version R2023b
|
2 |
+
perspectives: 000000ff00000000fd0000000200000001000003520000030bfc0200000001fb0000001400540065007800740045006400690074006f007201000000000000030b0000008a00ffffff0000000300000700000000d9fc0100000001fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000000007000000008700ffffff000003ac0000030b00000001000000020000000100000008fc00000000
|
3 |
+
simulationViewPerspectives: 000000ff00000001000000020000016c000001950100000002010000000101
|
4 |
+
sceneTreePerspectives: 000000ff00000001000000030000001e000000c0000000fa0100000002010000000201
|
5 |
+
maximizedDockId: -1
|
6 |
+
centralWidgetVisible: 1
|
7 |
+
orthographicViewHeight: 1
|
8 |
+
textFiles: 0 "controllers/datacollector/datacollector.py"
|
9 |
+
consoles: Console:All:All
|
10 |
+
renderingDevicePerspectives: UR5e:camera;1;0.210701;0.517958;0.360222
|
11 |
+
renderingDevicePerspectives: UR5e:realsenseD405;1;0.22713;0.490023;0.036161
|
worlds/webots_grasp.wbt
ADDED
The diff for this file is too large to render.
See raw diff
|
|