From c639072a3af73cdd28c33c02cb18abdbd9a261c8 Mon Sep 17 00:00:00 2001 From: Keya Loding Date: Wed, 10 Jul 2024 21:43:48 -0700 Subject: [PATCH] a --- io_test.ipynb | 151 ++++++++++++++++++++++++++++++++------------ sleap_io/io/main.py | 12 ++-- 2 files changed, 118 insertions(+), 45 deletions(-) diff --git a/io_test.ipynb b/io_test.ipynb index b86e17a9..1a2b08e6 100644 --- a/io_test.ipynb +++ b/io_test.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 6, + "execution_count": 63, "metadata": {}, "outputs": [ { @@ -38,38 +38,81 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 64, "metadata": {}, "outputs": [ { - "ename": "ValueError", - "evalue": "'skeleton_instance' already exists in SkeletonInstances 'skeleton_instances'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[7], line 12\u001b[0m\n\u001b[1;32m 9\u001b[0m inst\u001b[38;5;241m.\u001b[39mskeleton\u001b[38;5;241m.\u001b[39medges \u001b[38;5;241m=\u001b[39m [Edge(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mA\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mB\u001b[39m\u001b[38;5;124m\"\u001b[39m)]\n\u001b[1;32m 10\u001b[0m instance_to_skeleton_instance(inst)\n\u001b[0;32m---> 12\u001b[0m \u001b[43mlabels_to_pose_training\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlabels_original\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/salk/io_fork/sleap_io/io/nwb.py:94\u001b[0m, in \u001b[0;36mlabels_to_pose_training\u001b[0;34m(labels, **kwargs)\u001b[0m\n\u001b[1;32m 91\u001b[0m skeleton_instance \u001b[38;5;241m=\u001b[39m instance_to_skeleton_instance(instance)\n\u001b[1;32m 92\u001b[0m skeleton_instances_list\u001b[38;5;241m.\u001b[39mappend(skeleton_instance)\n\u001b[0;32m---> 94\u001b[0m training_frame_skeleton_instances \u001b[38;5;241m=\u001b[39m \u001b[43mSkeletonInstances\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 95\u001b[0m \u001b[43m \u001b[49m\u001b[43mskeleton_instances\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mskeleton_instances_list\u001b[49m\n\u001b[1;32m 96\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 97\u001b[0m training_frame_video \u001b[38;5;241m=\u001b[39m labeled_frame\u001b[38;5;241m.\u001b[39mvideo\n\u001b[1;32m 98\u001b[0m training_frame_video_index \u001b[38;5;241m=\u001b[39m labeled_frame\u001b[38;5;241m.\u001b[39mframe_idx\n", - "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/hdmf/utils.py:668\u001b[0m, in \u001b[0;36mdocval..dec..func_call\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 666\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfunc_call\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 667\u001b[0m pargs \u001b[38;5;241m=\u001b[39m _check_args(args, kwargs)\n\u001b[0;32m--> 668\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mpargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/hdmf/build/classgenerator.py:357\u001b[0m, in \u001b[0;36mCustomClassGenerator.set_init..__init__\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 353\u001b[0m \u001b[38;5;66;03m# TODO should super() be used above instead of base?\u001b[39;00m\n\u001b[1;32m 354\u001b[0m \n\u001b[1;32m 355\u001b[0m \u001b[38;5;66;03m# set the fields that are new to this class (not inherited)\u001b[39;00m\n\u001b[1;32m 356\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m f, arg_val \u001b[38;5;129;01min\u001b[39;00m new_kwargs\u001b[38;5;241m.\u001b[39mitems():\n\u001b[0;32m--> 357\u001b[0m \u001b[38;5;28;43msetattr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43marg_val\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 359\u001b[0m \u001b[38;5;66;03m# set the fields that have fixed values using the fields dict directly\u001b[39;00m\n\u001b[1;32m 360\u001b[0m \u001b[38;5;66;03m# because the setters do not allow setting the value\u001b[39;00m\n\u001b[1;32m 361\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m f \u001b[38;5;129;01min\u001b[39;00m fixed_value_attrs_to_set:\n", - "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/hdmf/utils.py:668\u001b[0m, in \u001b[0;36mdocval..dec..func_call\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 666\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfunc_call\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 667\u001b[0m pargs \u001b[38;5;241m=\u001b[39m _check_args(args, kwargs)\n\u001b[0;32m--> 668\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mpargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/hdmf/container.py:1215\u001b[0m, in \u001b[0;36mMultiContainerInterface.__make_setter.._func\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 1213\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m val \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 1214\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[0;32m-> 1215\u001b[0m \u001b[38;5;28;43mgetattr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43madd_name\u001b[49m\u001b[43m)\u001b[49m\u001b[43m(\u001b[49m\u001b[43mval\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/hdmf/utils.py:668\u001b[0m, in \u001b[0;36mdocval..dec..func_call\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 666\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfunc_call\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 667\u001b[0m pargs \u001b[38;5;241m=\u001b[39m _check_args(args, kwargs)\n\u001b[0;32m--> 668\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mpargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/hdmf/container.py:1146\u001b[0m, in \u001b[0;36mMultiContainerInterface.__make_add.._func\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 1144\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tmp\u001b[38;5;241m.\u001b[39mname \u001b[38;5;129;01min\u001b[39;00m d:\n\u001b[1;32m 1145\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m already exists in \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m (tmp\u001b[38;5;241m.\u001b[39mname, \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname)\n\u001b[0;32m-> 1146\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(msg)\n\u001b[1;32m 1147\u001b[0m d[tmp\u001b[38;5;241m.\u001b[39mname] \u001b[38;5;241m=\u001b[39m tmp\n\u001b[1;32m 1148\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m container\n", - "\u001b[0;31mValueError\u001b[0m: 'skeleton_instance' already exists in SkeletonInstances 'skeleton_instances'" - ] + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + "

PoseTraining

training_frames
training_frames
training_frame44
annotator: training_frame440
source_video_frame_index0
skeleton_instances
skeleton_instances
skeleton_instance70
id10
node_locations
[[ 92.65220773 202.72597774]
[152.34188116 158.42364351]]
node_visibility
0: True
1: True
skeleton
nodes
0: A
1: B
edges
[[0 1]]
skeleton_instance71
id10
node_locations
[[205.9300539 187.88964024]
[278.63521449 203.36586573]]
node_visibility
0: True
1: True
skeleton
nodes
0: A
1: B
edges
[[0 1]]
source_video
rate: 30.0
resolution: -1.0
comments: no comments
description: training_frame440
conversion: 1.0
offset: 0.0
unit: NA
data
[]
starting_time: 0.0
starting_time_unit: seconds
dimension
0: 384
1: 384
external_file
0: tests/data/slp/minimal_instance.pkg.slp
starting_frame
0: 0
format: external
source_videos
image_series
video_0
rate: 30.0
resolution: -1.0
comments: no comments
description: Video file
conversion: 1.0
offset: 0.0
unit: NA
data
[]
starting_time: 0.0
starting_time_unit: seconds
dimension
0: 384
1: 384
external_file
0: tests/data/slp/minimal_instance.pkg.slp
starting_frame
0: 0
format: external
" + ], + "text/plain": [ + "PoseTraining abc.PoseTraining at 0x4342072624\n", + "Fields:\n", + " source_videos: source_videos abc.SourceVideos at 0x5743911680\n", + "Fields:\n", + " image_series: {\n", + " video_0 \n", + " }\n", + "\n", + " training_frames: training_frames abc.TrainingFrames at 0x4342072912\n", + "Fields:\n", + " training_frames: {\n", + " training_frame44 \n", + " }\n" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ "labels_original = sio.load_slp(\"tests/data/slp/minimal_instance.pkg.slp\")\n", "skel = Skeleton([Node(\"A\"), Node(\"B\")])\n", "skel.name = \"name\"\n", - "skel.edges = [Edge(\"A\", \"B\")]\n", + "skel.edges = [Edge(Node(\"A\"), Node(\"B\"))]\n", "slp_skeleton_to_nwb(skel)\n", "\n", "inst = Instance({\"A\": [0, 1], \"B\": [2, 3]}, skeleton=Skeleton([\"A\", \"B\"]))\n", "inst.skeleton.name = \"name\"\n", - "inst.skeleton.edges = [Edge(\"A\", \"B\")]\n", + "inst.skeleton.edges = [Edge(Node(\"A\"), Node(\"B\"))]\n", "instance_to_skeleton_instance(inst)\n", "\n", "labels_to_pose_training(labels_original)" @@ -77,29 +120,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "training_frames abc.TrainingFrames at 0x5737829616\n", + "Fields:\n", + " training_frames: {\n", + " training_frame46 \n", + " }\n", + "\n", + "source_videos abc.SourceVideos at 0x5697520512\n", + "Fields:\n", + " image_series: {\n", + " video_0 \n", + " }\n", + "\n" + ] + }, { "ename": "TypeError", - "evalue": "CustomClassGenerator.set_init..__init__: incorrect type for 'name' (got 'list', expected 'str')", + "evalue": "write_nwb_training() got an unexpected keyword argument 'embed'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[3], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m labels_original \u001b[38;5;241m=\u001b[39m sio\u001b[38;5;241m.\u001b[39mload_slp(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtests/data/slp/minimal_instance.pkg.slp\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m \u001b[43mlabels_original\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msave\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mminimal_instance.pkg.nwb\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mnwb_training\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m labels_loaded \u001b[38;5;241m=\u001b[39m sio\u001b[38;5;241m.\u001b[39mload_nwb(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mminimal_instance.pkg.nwb\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m labels_original\u001b[38;5;241m.\u001b[39mlabeled_frames \u001b[38;5;241m==\u001b[39m labels_loaded\u001b[38;5;241m.\u001b[39mlabeled_frames\n", + "Cell \u001b[0;32mIn[66], line 5\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(pose\u001b[38;5;241m.\u001b[39mtraining_frames)\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(pose\u001b[38;5;241m.\u001b[39msource_videos)\n\u001b[0;32m----> 5\u001b[0m \u001b[43mlabels_original\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msave\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mminimal_instance.pkg.nwb\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mnwb_training\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7\u001b[0m labels_loaded \u001b[38;5;241m=\u001b[39m sio\u001b[38;5;241m.\u001b[39mload_nwb(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mminimal_instance.pkg.nwb\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m labels_original\u001b[38;5;241m.\u001b[39mlabeled_frames \u001b[38;5;241m==\u001b[39m labels_loaded\u001b[38;5;241m.\u001b[39mlabeled_frames\n", "File \u001b[0;32m~/salk/io_fork/sleap_io/model/labels.py:372\u001b[0m, in \u001b[0;36mLabels.save\u001b[0;34m(self, filename, format, embed, **kwargs)\u001b[0m\n\u001b[1;32m 348\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Save labels to file in specified format.\u001b[39;00m\n\u001b[1;32m 349\u001b[0m \n\u001b[1;32m 350\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 368\u001b[0m \u001b[38;5;124;03m This argument is only valid for the SLP backend.\u001b[39;00m\n\u001b[1;32m 369\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 370\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msleap_io\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m save_file\n\u001b[0;32m--> 372\u001b[0m \u001b[43msave_file\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43membed\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43membed\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/salk/io_fork/sleap_io/io/main.py:232\u001b[0m, in \u001b[0;36msave_file\u001b[0;34m(labels, filename, format, **kwargs)\u001b[0m\n\u001b[1;32m 230\u001b[0m save_jabs(labels, pose_version, filename, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 231\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnwb_training\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 232\u001b[0m \u001b[43mnwb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlabels_to_pose_training\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlabels\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 233\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 234\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUnknown format \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mformat\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m for filename: \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfilename\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "File \u001b[0;32m~/salk/io_fork/sleap_io/io/nwb.py:94\u001b[0m, in \u001b[0;36mlabels_to_pose_training\u001b[0;34m(labels, **kwargs)\u001b[0m\n\u001b[1;32m 91\u001b[0m skeleton_instance \u001b[38;5;241m=\u001b[39m instance_to_skeleton_instance(instance)\n\u001b[1;32m 92\u001b[0m skeleton_instances_list\u001b[38;5;241m.\u001b[39mappend(skeleton_instance)\n\u001b[0;32m---> 94\u001b[0m training_frame_skeleton_instances \u001b[38;5;241m=\u001b[39m \u001b[43mSkeletonInstances\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 95\u001b[0m \u001b[43m \u001b[49m\u001b[43mskeleton_instances_list\u001b[49m\n\u001b[1;32m 96\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 97\u001b[0m training_frame_video \u001b[38;5;241m=\u001b[39m labeled_frame\u001b[38;5;241m.\u001b[39mvideo\n\u001b[1;32m 98\u001b[0m training_frame_video_index \u001b[38;5;241m=\u001b[39m labeled_frame\u001b[38;5;241m.\u001b[39mframe_idx\n", - "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/hdmf/utils.py:667\u001b[0m, in \u001b[0;36mdocval..dec..func_call\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 666\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfunc_call\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m--> 667\u001b[0m pargs \u001b[38;5;241m=\u001b[39m \u001b[43m_check_args\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 668\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(args[\u001b[38;5;241m0\u001b[39m], \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mpargs)\n", - "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/hdmf/utils.py:660\u001b[0m, in \u001b[0;36mdocval..dec.._check_args\u001b[0;34m(args, kwargs)\u001b[0m\n\u001b[1;32m 658\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m parse_err:\n\u001b[1;32m 659\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m%\u001b[39m (func\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__qualname__\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin(parse_err))\n\u001b[0;32m--> 660\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ExceptionType(msg)\n\u001b[1;32m 662\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m parsed[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124margs\u001b[39m\u001b[38;5;124m'\u001b[39m]\n", - "\u001b[0;31mTypeError\u001b[0m: CustomClassGenerator.set_init..__init__: incorrect type for 'name' (got 'list', expected 'str')" + "File \u001b[0;32m~/salk/io_fork/sleap_io/io/main.py:238\u001b[0m, in \u001b[0;36msave_file\u001b[0;34m(labels, filename, format, **kwargs)\u001b[0m\n\u001b[1;32m 236\u001b[0m save_slp(labels, filename, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 237\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnwb\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnwb_training\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 238\u001b[0m \u001b[43msave_nwb\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlabels\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 239\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlabelstudio\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 240\u001b[0m save_labelstudio(labels, filename, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "File \u001b[0;32m~/salk/io_fork/sleap_io/io/main.py:89\u001b[0m, in \u001b[0;36msave_nwb\u001b[0;34m(labels, filename, format, append, **kwargs)\u001b[0m\n\u001b[1;32m 87\u001b[0m nwb\u001b[38;5;241m.\u001b[39mappend_nwb_training(pose_training, filename, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 88\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m---> 89\u001b[0m \u001b[43mnwb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwrite_nwb_training\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpose_training\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mTypeError\u001b[0m: write_nwb_training() got an unexpected keyword argument 'embed'" ] } ], "source": [ "labels_original = sio.load_slp(\"tests/data/slp/minimal_instance.pkg.slp\")\n", + "pose = labels_to_pose_training(labels_original)\n", + "print(pose.training_frames)\n", + "print(pose.source_videos)\n", "labels_original.save(\"minimal_instance.pkg.nwb\", format=\"nwb_training\")\n", + "\n", "labels_loaded = sio.load_nwb(\"minimal_instance.pkg.nwb\")\n", "assert labels_original.labeled_frames == labels_loaded.labeled_frames\n", "assert labels_original.videos == labels_loaded.videos\n", @@ -115,31 +178,41 @@ "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "descriptor 'keep_open' for 'VideoBackend' objects doesn't apply to a 'HDF5Video' object", + "name": "stdout", + "output_type": "stream", + "text": [ + "minimal_instance.pkg.nwb_images/Video(filename=\"tests/data/slp/minimal_instance.pkg.slp\", shape=(1, 384, 384, 1), dataset=video0/video, backend=HDF5Video).0.png\n" + ] + }, + { + "ename": "FileNotFoundError", + "evalue": "The directory '/Users/keya/salk/io_fork/minimal_instance.pkg.nwb_images/Video(filename=\"tests/data/slp/minimal_instance.pkg.slp\", shape=(1, 384, 384, 1), dataset=video0' does not exist", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[55], line 7\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, lf \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(labels_original):\n\u001b[1;32m 6\u001b[0m img_path \u001b[38;5;241m=\u001b[39m save_path \u001b[38;5;241m/\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlabels_original\u001b[38;5;241m.\u001b[39mlabeled_frames[i]\u001b[38;5;241m.\u001b[39mvideo\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlf\u001b[38;5;241m.\u001b[39mframe_idx\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.png\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 7\u001b[0m iio\u001b[38;5;241m.\u001b[39mimwrite(img_path, \u001b[43mlf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimage\u001b[49m)\n\u001b[1;32m 8\u001b[0m img_paths\u001b[38;5;241m.\u001b[39mappend(img_path)\n", - "File \u001b[0;32m~/salk/io_fork/sleap_io/model/labeled_frame.py:89\u001b[0m, in \u001b[0;36mLabeledFrame.image\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[38;5;129m@property\u001b[39m\n\u001b[1;32m 87\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mimage\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m np\u001b[38;5;241m.\u001b[39mndarray:\n\u001b[1;32m 88\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Return the image of the frame as a numpy array.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 89\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvideo\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mframe_idx\u001b[49m\u001b[43m]\u001b[49m\n", - "File \u001b[0;32m~/salk/io_fork/sleap_io/model/video.py:185\u001b[0m, in \u001b[0;36mVideo.__getitem__\u001b[0;34m(self, inds)\u001b[0m\n\u001b[1;32m 183\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mis_open:\n\u001b[1;32m 184\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mopen()\n\u001b[0;32m--> 185\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackend\u001b[49m\u001b[43m[\u001b[49m\u001b[43minds\u001b[49m\u001b[43m]\u001b[49m\n", - "File \u001b[0;32m~/salk/io_fork/sleap_io/io/video.py:271\u001b[0m, in \u001b[0;36mVideoBackend.__getitem__\u001b[0;34m(self, ind)\u001b[0m\n\u001b[1;32m 258\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Return a single frame or a list of frames from the video.\u001b[39;00m\n\u001b[1;32m 259\u001b[0m \n\u001b[1;32m 260\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 268\u001b[0m \u001b[38;5;124;03mSee also: get_frame, get_frames\u001b[39;00m\n\u001b[1;32m 269\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 270\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m np\u001b[38;5;241m.\u001b[39misscalar(ind):\n\u001b[0;32m--> 271\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_frame\u001b[49m\u001b[43m(\u001b[49m\u001b[43mind\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 272\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 273\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mtype\u001b[39m(ind) \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28mslice\u001b[39m:\n", - "File \u001b[0;32m~/salk/io_fork/sleap_io/io/video.py:215\u001b[0m, in \u001b[0;36mVideoBackend.get_frame\u001b[0;34m(self, frame_idx)\u001b[0m\n\u001b[1;32m 196\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_frame\u001b[39m(\u001b[38;5;28mself\u001b[39m, frame_idx: \u001b[38;5;28mint\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m np\u001b[38;5;241m.\u001b[39mndarray:\n\u001b[1;32m 197\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Read a single frame from the video.\u001b[39;00m\n\u001b[1;32m 198\u001b[0m \n\u001b[1;32m 199\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 213\u001b[0m \u001b[38;5;124;03m See also: `get_frames`\u001b[39;00m\n\u001b[1;32m 214\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 215\u001b[0m img \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_read_frame\u001b[49m\u001b[43m(\u001b[49m\u001b[43mframe_idx\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 217\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mgrayscale \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 218\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdetect_grayscale(img)\n", - "File \u001b[0;32m~/salk/io_fork/sleap_io/io/video.py:630\u001b[0m, in \u001b[0;36m_read_frame\u001b[0;34m(self, frame_idx)\u001b[0m\n\u001b[1;32m 623\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_read_frame\u001b[39m(\u001b[38;5;28mself\u001b[39m, frame_idx: \u001b[38;5;28mint\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m np\u001b[38;5;241m.\u001b[39mndarray:\n\u001b[1;32m 624\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Read a single frame from the video.\u001b[39;00m\n\u001b[1;32m 625\u001b[0m \n\u001b[1;32m 626\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[1;32m 627\u001b[0m \u001b[38;5;124;03m frame_idx: Index of frame to read.\u001b[39;00m\n\u001b[1;32m 628\u001b[0m \n\u001b[1;32m 629\u001b[0m \u001b[38;5;124;03m Returns:\u001b[39;00m\n\u001b[0;32m--> 630\u001b[0m \u001b[38;5;124;03m The frame as a numpy array of shape `(height, width, channels)`.\u001b[39;00m\n\u001b[1;32m 631\u001b[0m \n\u001b[1;32m 632\u001b[0m \u001b[38;5;124;03m Notes:\u001b[39;00m\n\u001b[1;32m 633\u001b[0m \u001b[38;5;124;03m This does not apply grayscale conversion. It is recommended to use the\u001b[39;00m\n\u001b[1;32m 634\u001b[0m \u001b[38;5;124;03m `get_frame` method of the `VideoBackend` class instead.\u001b[39;00m\n\u001b[1;32m 635\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 636\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkeep_open:\n\u001b[1;32m 637\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_open_reader \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", - "\u001b[0;31mTypeError\u001b[0m: descriptor 'keep_open' for 'VideoBackend' objects doesn't apply to a 'HDF5Video' object" + "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[3], line 10\u001b[0m\n\u001b[1;32m 8\u001b[0m img_path \u001b[38;5;241m=\u001b[39m save_path \u001b[38;5;241m/\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlabels_original\u001b[38;5;241m.\u001b[39mlabeled_frames[i]\u001b[38;5;241m.\u001b[39mvideo\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mlf\u001b[38;5;241m.\u001b[39mframe_idx\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.png\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(img_path)\n\u001b[0;32m---> 10\u001b[0m \u001b[43miio\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimwrite\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimg_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimage\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 11\u001b[0m img_paths\u001b[38;5;241m.\u001b[39mappend(img_path)\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(img_paths)\n", + "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/imageio/v3.py:139\u001b[0m, in \u001b[0;36mimwrite\u001b[0;34m(uri, image, plugin, extension, format_hint, **kwargs)\u001b[0m\n\u001b[1;32m 104\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mimwrite\u001b[39m(uri, image, \u001b[38;5;241m*\u001b[39m, plugin\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, extension\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, format_hint\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 105\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Write an ndimage to the given URI.\u001b[39;00m\n\u001b[1;32m 106\u001b[0m \n\u001b[1;32m 107\u001b[0m \u001b[38;5;124;03m The exact behavior depends on the file type and plugin used. To learn about\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 136\u001b[0m \n\u001b[1;32m 137\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 139\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[43mimopen\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 140\u001b[0m \u001b[43m \u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 141\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mw\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 142\u001b[0m \u001b[43m \u001b[49m\u001b[43mlegacy_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 143\u001b[0m \u001b[43m \u001b[49m\u001b[43mplugin\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mplugin\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 144\u001b[0m \u001b[43m \u001b[49m\u001b[43mformat_hint\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mformat_hint\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 145\u001b[0m \u001b[43m \u001b[49m\u001b[43mextension\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextension\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 146\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m img_file:\n\u001b[1;32m 147\u001b[0m encoded \u001b[38;5;241m=\u001b[39m img_file\u001b[38;5;241m.\u001b[39mwrite(image, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 149\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m encoded\n", + "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/imageio/core/imopen.py:113\u001b[0m, in \u001b[0;36mimopen\u001b[0;34m(uri, io_mode, plugin, extension, format_hint, legacy_mode, **kwargs)\u001b[0m\n\u001b[1;32m 111\u001b[0m request\u001b[38;5;241m.\u001b[39mformat_hint \u001b[38;5;241m=\u001b[39m format_hint\n\u001b[1;32m 112\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 113\u001b[0m request \u001b[38;5;241m=\u001b[39m \u001b[43mRequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43muri\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mio_mode\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mformat_hint\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mformat_hint\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextension\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextension\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 115\u001b[0m source \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(uri, \u001b[38;5;28mbytes\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m uri\n\u001b[1;32m 117\u001b[0m \u001b[38;5;66;03m# fast-path based on plugin\u001b[39;00m\n\u001b[1;32m 118\u001b[0m \u001b[38;5;66;03m# (except in legacy mode)\u001b[39;00m\n", + "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/imageio/core/request.py:247\u001b[0m, in \u001b[0;36mRequest.__init__\u001b[0;34m(self, uri, mode, extension, format_hint, **kwargs)\u001b[0m\n\u001b[1;32m 244\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Request.Mode: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmode\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 246\u001b[0m \u001b[38;5;66;03m# Parse what was given\u001b[39;00m\n\u001b[0;32m--> 247\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parse_uri\u001b[49m\u001b[43m(\u001b[49m\u001b[43muri\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 249\u001b[0m \u001b[38;5;66;03m# Set extension\u001b[39;00m\n\u001b[1;32m 250\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m extension \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", + "File \u001b[0;32m~/mambaforge3/envs/io_dev/lib/python3.12/site-packages/imageio/core/request.py:412\u001b[0m, in \u001b[0;36mRequest._parse_uri\u001b[0;34m(self, uri)\u001b[0m\n\u001b[1;32m 410\u001b[0m dn \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mdirname(fn)\n\u001b[1;32m 411\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexists(dn):\n\u001b[0;32m--> 412\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mFileNotFoundError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe directory \u001b[39m\u001b[38;5;132;01m%r\u001b[39;00m\u001b[38;5;124m does not exist\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m dn)\n", + "\u001b[0;31mFileNotFoundError\u001b[0m: The directory '/Users/keya/salk/io_fork/minimal_instance.pkg.nwb_images/Video(filename=\"tests/data/slp/minimal_instance.pkg.slp\", shape=(1, 384, 384, 1), dataset=video0' does not exist" ] } ], "source": [ "import imageio.v3 as iio\n", "from pathlib import Path\n", + "import sleap_io as sio\n", "save_path = Path(\"minimal_instance.pkg.nwb_images\")\n", "img_paths = []\n", + "labels_original = sio.load_slp(\"tests/data/slp/minimal_instance.pkg.slp\")\n", "for i, lf in enumerate(labels_original):\n", " img_path = save_path / f\"{labels_original.labeled_frames[i].video}.{lf.frame_idx}.png\"\n", + " print(img_path)\n", " iio.imwrite(img_path, lf.image)\n", - " img_paths.append(img_path)" + " img_paths.append(img_path)\n", + "print(img_paths)" ] } ], diff --git a/sleap_io/io/main.py b/sleap_io/io/main.py index b1919189..6035bf2d 100644 --- a/sleap_io/io/main.py +++ b/sleap_io/io/main.py @@ -81,12 +81,12 @@ def save_nwb(labels: Labels, filename: str, format: str, append: bool = True, ** else: nwb.write_nwb(labels, filename, **kwargs) - # elif format == "nwb_training": - # pose_training = nwb.labels_to_pose_training(labels, **kwargs) - # if append and Path(filename).exists(): - # nwb.append_nwb_training(pose_training, filename, **kwargs) - # else: - # nwb.write_nwb_training(pose_training, filename, **kwargs) + elif format == "nwb_training": + pose_training = nwb.labels_to_pose_training(labels, **kwargs) + if append and Path(filename).exists(): + nwb.append_nwb_training(pose_training, filename, **kwargs) + else: + nwb.write_nwb_training(pose_training, filename, **kwargs) def load_labelstudio(