Recording
Module for recording data to an h5 file.
Recorder
Records a dataset to an h5 file. Saves images defined to folder with _frames appended to the name stem.
Example
# Define the observation and action spaces
observation_space = spaces.Dict(
{"image": spaces.Box(low=0, high=255, shape=(224, 224, 3), dtype=np.uint8), "instruction": spaces.Discrete(10)}
)
action_space = spaces.Dict(
{
"gripper_position": spaces.Box(low=-1, high=1, shape=(3,), dtype=np.float32),
"gripper_action": spaces.Discrete(2),
}
)
state_space = spaces.Dict(
{
"position": spaces.Box(low=-1, high=1, shape=(3,), dtype=np.float32),
"velocity": spaces.Box(low=-1, high=1, shape=(3,), dtype=np.float32),
}
)
# Create a recorder instance
recorder = Recorder(
name="test_recorder", observation_space=observation_space, action_space=action_space, state_space=state_space
)
# Generate some sample data
num_steps = 10
for i in range(num_steps):
observation = {"image": np.ones((224, 224, 3), dtype=np.uint8), "instruction": i}
action = {"gripper_position": np.zeros((3,), dtype=np.float32), "gripper_action": 1}
state = {"position": np.random.rand(3).astype(np.float32), "velocity": np.random.rand(3).astype(np.float32)}
recorder.record(observation, action, state=state)
# Save the statistics
recorder.save_stats()
# Close the recorder
recorder.close()
# Assert that the HDF5 file and directories are created
assert os.path.exists("test_recorder.h5")
assert os.path.exists("test_recorder_frames")
Source code in mbodied/data/recording.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
__init__(name='dataset.h5', observation_space=None, action_space=None, state_space=None, supervision_space=None, out_dir='saved_datasets', image_keys_to_save=None)
Initialize the Recorder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the file. |
'dataset.h5'
|
observation_space
|
Dict
|
Observation space. |
None
|
action_space
|
Dict
|
Action space. |
None
|
state_space
|
Dict
|
State space. |
None
|
supervision_space
|
Dict
|
Supervision space. |
None
|
out_dir
|
str
|
Directory of the output file. Defaults to 'saved_datasets'. |
'saved_datasets'
|
image_keys_to_save
|
list
|
List of image keys to save. Defaults to ['image']. |
None
|
Source code in mbodied/data/recording.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
close()
Closes the Recorder and send the data if train_config is set.
Source code in mbodied/data/recording.py
335 336 337 |
|
configure_root_spaces(**spaces)
Configure the root spaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**spaces
|
Dict
|
Spaces to configure. observation_space (spaces.Dict): Observation space. action_space (spaces.Dict): Action space. state_space (spaces.Dict): State space. supervision_space (spaces.Dict): Supervision space. |
{}
|
Source code in mbodied/data/recording.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
record(observation=None, action=None, state=None, supervision=None)
Record a timestep.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
Any
|
Observation to record. |
None
|
action
|
Any
|
Action to record. |
None
|
state
|
Any
|
State to record. |
None
|
supervision
|
Any
|
Supervision to record. |
None
|
Source code in mbodied/data/recording.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
record_timestep(group, sample, index)
Record a timestep.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group
|
Group
|
Group to record to. |
required |
sample
|
Any
|
Sample to record. |
required |
index
|
int
|
Index to record at. |
required |
Source code in mbodied/data/recording.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
reset()
Reset the recorder.
Source code in mbodied/data/recording.py
189 190 191 192 193 |
|