KillzoneCC commited on
Commit ·
024a5cb
1
Parent(s): 7459482
Поправки
Browse files- collect_and_upload.py +38 -26
collect_and_upload.py
CHANGED
|
@@ -222,6 +222,8 @@ def create_video(frames, video_path):
|
|
| 222 |
video_writer.release()
|
| 223 |
print(f"Видеофайл успешно создан: {video_path}")
|
| 224 |
|
|
|
|
|
|
|
| 225 |
def collect_data_and_save():
|
| 226 |
global running
|
| 227 |
|
|
@@ -263,6 +265,8 @@ def collect_data_and_save():
|
|
| 263 |
os.remove(info_path)
|
| 264 |
|
| 265 |
if not info:
|
|
|
|
|
|
|
| 266 |
info = {
|
| 267 |
"codebase_version": "v1.1",
|
| 268 |
"total_frames": 0,
|
|
@@ -273,9 +277,13 @@ def collect_data_and_save():
|
|
| 273 |
"data_path": "data/chunk-000/episode_{episode_index:06d}.parquet",
|
| 274 |
"video_path": "videos/chunk-000/observation.images.generic/episode_{episode_index:06d}.mp4",
|
| 275 |
"features": {
|
| 276 |
-
"action": {
|
|
|
|
|
|
|
|
|
|
| 277 |
"observation": {
|
| 278 |
-
"
|
|
|
|
| 279 |
"images.generic": {
|
| 280 |
"dtype": "video",
|
| 281 |
"media_type": "video/mp4",
|
|
@@ -335,8 +343,10 @@ features:
|
|
| 335 |
current_episode_start_time = time.time()
|
| 336 |
|
| 337 |
all_images_generic = []
|
| 338 |
-
|
| 339 |
-
|
|
|
|
|
|
|
| 340 |
all_timestamps = []
|
| 341 |
all_frame_indices = []
|
| 342 |
|
|
@@ -350,19 +360,17 @@ features:
|
|
| 350 |
if new_image_generic_data is not None:
|
| 351 |
img_generic, img_timestamp = new_image_generic_data
|
| 352 |
|
| 353 |
-
#
|
| 354 |
imu_data = latest_data["imu"][0] if latest_data["imu"] is not None else np.array([0.0]*10, dtype=np.float32)
|
| 355 |
joint_positions_obs_data = latest_data["joint_positions_obs"][0] if latest_data["joint_positions_obs"] is not None else np.array([0.0]*26, dtype=np.float32)
|
| 356 |
-
observation_state_data = np.concatenate([joint_positions_obs_data, imu_data])
|
| 357 |
-
|
| 358 |
-
# Объединение action
|
| 359 |
joint_positions_action_data = latest_data["joint_positions_action"][0] if latest_data["joint_positions_action"] is not None else np.array([0.0]*26, dtype=np.float32)
|
| 360 |
joy_data = latest_data["joy"][0] if latest_data["joy"] is not None else np.array([0.0]*10, dtype=np.float32)
|
| 361 |
-
action_data = np.concatenate([joint_positions_action_data, joy_data])
|
| 362 |
|
| 363 |
all_images_generic.append(img_generic)
|
| 364 |
-
|
| 365 |
-
|
|
|
|
|
|
|
| 366 |
all_timestamps.append(img_timestamp)
|
| 367 |
all_frame_indices.append(len(all_images_generic) - 1)
|
| 368 |
|
|
@@ -376,16 +384,17 @@ features:
|
|
| 376 |
video_path_generic = VIDEOS_DIR / f"episode_{episode_idx:06d}.mp4"
|
| 377 |
create_video(all_images_generic, video_path_generic)
|
| 378 |
|
| 379 |
-
#
|
| 380 |
df = pd.DataFrame({
|
| 381 |
-
'index': list(range(len(all_images_generic))),
|
| 382 |
-
'task_index': [0] * len(all_images_generic), # Используем первый таск для примера
|
| 383 |
-
'episode_index': [episode_idx] * len(all_images_generic),
|
| 384 |
-
'frame_index': all_frame_indices,
|
| 385 |
-
'action': all_actions,
|
| 386 |
-
'observation.state': all_observation_states,
|
| 387 |
'observation.images.generic': [f"../../videos/chunk-000/observation.images.generic/episode_{episode_idx:06d}.mp4"] * len(all_images_generic),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
'timestamp': all_timestamps,
|
|
|
|
|
|
|
|
|
|
| 389 |
})
|
| 390 |
|
| 391 |
table = pa.Table.from_pandas(df)
|
|
@@ -409,8 +418,10 @@ features:
|
|
| 409 |
episode_idx += 1
|
| 410 |
current_episode_start_time = time.time()
|
| 411 |
all_images_generic = []
|
| 412 |
-
|
| 413 |
-
|
|
|
|
|
|
|
| 414 |
all_timestamps = []
|
| 415 |
all_frame_indices = []
|
| 416 |
|
|
@@ -426,14 +437,15 @@ features:
|
|
| 426 |
create_video(all_images_generic, video_path_generic)
|
| 427 |
|
| 428 |
df = pd.DataFrame({
|
| 429 |
-
'index': list(range(len(all_images_generic))),
|
| 430 |
-
'task_index': [0] * len(all_images_generic),
|
| 431 |
-
'episode_index': [episode_idx] * len(all_images_generic),
|
| 432 |
-
'frame_index': all_frame_indices,
|
| 433 |
-
'action': all_actions,
|
| 434 |
-
'observation.state': all_observation_states,
|
| 435 |
'observation.images.generic': [f"../../videos/chunk-000/observation.images.generic/episode_{episode_idx:06d}.mp4"] * len(all_images_generic),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
'timestamp': all_timestamps,
|
|
|
|
|
|
|
|
|
|
| 437 |
})
|
| 438 |
|
| 439 |
table = pa.Table.from_pandas(df)
|
|
|
|
| 222 |
video_writer.release()
|
| 223 |
print(f"Видеофайл успешно создан: {video_path}")
|
| 224 |
|
| 225 |
+
# ... (весь ваш код до функции collect_data_and_save) ...
|
| 226 |
+
|
| 227 |
def collect_data_and_save():
|
| 228 |
global running
|
| 229 |
|
|
|
|
| 265 |
os.remove(info_path)
|
| 266 |
|
| 267 |
if not info:
|
| 268 |
+
# Убедитесь, что эта структура соответствует тому, что вы собираете.
|
| 269 |
+
# Я изменил ее, чтобы она была более детализированной.
|
| 270 |
info = {
|
| 271 |
"codebase_version": "v1.1",
|
| 272 |
"total_frames": 0,
|
|
|
|
| 277 |
"data_path": "data/chunk-000/episode_{episode_index:06d}.parquet",
|
| 278 |
"video_path": "videos/chunk-000/observation.images.generic/episode_{episode_index:06d}.mp4",
|
| 279 |
"features": {
|
| 280 |
+
"action": {
|
| 281 |
+
"servo_commands": { "dtype": "float32", "shape": [26] },
|
| 282 |
+
"joy": { "dtype": "float32", "shape": [10] }
|
| 283 |
+
},
|
| 284 |
"observation": {
|
| 285 |
+
"joint_positions": { "dtype": "float32", "shape": [26] },
|
| 286 |
+
"imu": { "dtype": "float32", "shape": [10] },
|
| 287 |
"images.generic": {
|
| 288 |
"dtype": "video",
|
| 289 |
"media_type": "video/mp4",
|
|
|
|
| 343 |
current_episode_start_time = time.time()
|
| 344 |
|
| 345 |
all_images_generic = []
|
| 346 |
+
all_joint_positions_obs = [] # Новый список для joint_positions
|
| 347 |
+
all_imu_data = [] # Новый список для imu
|
| 348 |
+
all_joint_positions_action = [] # Новый список для joint_positions_action
|
| 349 |
+
all_joy_data = [] # Новый список для joy
|
| 350 |
all_timestamps = []
|
| 351 |
all_frame_indices = []
|
| 352 |
|
|
|
|
| 360 |
if new_image_generic_data is not None:
|
| 361 |
img_generic, img_timestamp = new_image_generic_data
|
| 362 |
|
| 363 |
+
# Получение отдельных компонентов наблюдения и действия
|
| 364 |
imu_data = latest_data["imu"][0] if latest_data["imu"] is not None else np.array([0.0]*10, dtype=np.float32)
|
| 365 |
joint_positions_obs_data = latest_data["joint_positions_obs"][0] if latest_data["joint_positions_obs"] is not None else np.array([0.0]*26, dtype=np.float32)
|
|
|
|
|
|
|
|
|
|
| 366 |
joint_positions_action_data = latest_data["joint_positions_action"][0] if latest_data["joint_positions_action"] is not None else np.array([0.0]*26, dtype=np.float32)
|
| 367 |
joy_data = latest_data["joy"][0] if latest_data["joy"] is not None else np.array([0.0]*10, dtype=np.float32)
|
|
|
|
| 368 |
|
| 369 |
all_images_generic.append(img_generic)
|
| 370 |
+
all_joint_positions_obs.append(joint_positions_obs_data.tolist())
|
| 371 |
+
all_imu_data.append(imu_data.tolist())
|
| 372 |
+
all_joint_positions_action.append(joint_positions_action_data.tolist())
|
| 373 |
+
all_joy_data.append(joy_data.tolist())
|
| 374 |
all_timestamps.append(img_timestamp)
|
| 375 |
all_frame_indices.append(len(all_images_generic) - 1)
|
| 376 |
|
|
|
|
| 384 |
video_path_generic = VIDEOS_DIR / f"episode_{episode_idx:06d}.mp4"
|
| 385 |
create_video(all_images_generic, video_path_generic)
|
| 386 |
|
| 387 |
+
# --- Исправленный DataFrame ---
|
| 388 |
df = pd.DataFrame({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
'observation.images.generic': [f"../../videos/chunk-000/observation.images.generic/episode_{episode_idx:06d}.mp4"] * len(all_images_generic),
|
| 390 |
+
'observation.joint_positions': all_joint_positions_obs,
|
| 391 |
+
'observation.imu': all_imu_data,
|
| 392 |
+
'action.servo_commands': all_joint_positions_action,
|
| 393 |
+
'action.joy': all_joy_data, # Добавляем joy как отдельное действие
|
| 394 |
'timestamp': all_timestamps,
|
| 395 |
+
'frame_index': all_frame_indices,
|
| 396 |
+
'episode_index': [episode_idx] * len(all_images_generic),
|
| 397 |
+
'task_index': [0] * len(all_images_generic),
|
| 398 |
})
|
| 399 |
|
| 400 |
table = pa.Table.from_pandas(df)
|
|
|
|
| 418 |
episode_idx += 1
|
| 419 |
current_episode_start_time = time.time()
|
| 420 |
all_images_generic = []
|
| 421 |
+
all_joint_positions_obs = []
|
| 422 |
+
all_imu_data = []
|
| 423 |
+
all_joint_positions_action = []
|
| 424 |
+
all_joy_data = []
|
| 425 |
all_timestamps = []
|
| 426 |
all_frame_indices = []
|
| 427 |
|
|
|
|
| 437 |
create_video(all_images_generic, video_path_generic)
|
| 438 |
|
| 439 |
df = pd.DataFrame({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
'observation.images.generic': [f"../../videos/chunk-000/observation.images.generic/episode_{episode_idx:06d}.mp4"] * len(all_images_generic),
|
| 441 |
+
'observation.joint_positions': all_joint_positions_obs,
|
| 442 |
+
'observation.imu': all_imu_data,
|
| 443 |
+
'action.servo_commands': all_joint_positions_action,
|
| 444 |
+
'action.joy': all_joy_data,
|
| 445 |
'timestamp': all_timestamps,
|
| 446 |
+
'frame_index': all_frame_indices,
|
| 447 |
+
'episode_index': [episode_idx] * len(all_images_generic),
|
| 448 |
+
'task_index': [0] * len(all_images_generic),
|
| 449 |
})
|
| 450 |
|
| 451 |
table = pa.Table.from_pandas(df)
|