|
| 1 | +import pyarrow as pa |
| 2 | + |
| 3 | +from eyepop.data.data_types import MIME_TYPE_APACHE_ARROW_FILE |
| 4 | + |
| 5 | +""" Arrow schema for Asset export/import form Data API. """ |
| 6 | + |
| 7 | +MIME_TYPE_APACHE_ARROW_FILE_VERSIONED = f"{MIME_TYPE_APACHE_ARROW_FILE};version=1.4" |
| 8 | + |
| 9 | + |
| 10 | +# BEGIN: Extension since v1.3 |
| 11 | +_embedding_fields = [ |
| 12 | + pa.field(name="embedding", type=pa.list_(pa.float16())), |
| 13 | + pa.field(name="x", type=pa.float16()), |
| 14 | + pa.field(name="y", type=pa.float16()), |
| 15 | + # BEGIN: Extension since v1.5 |
| 16 | + pa.field(name="category", type=pa.dictionary(pa.int32(), pa.string())), |
| 17 | + # END: Extension since v1.5 |
| 18 | +] |
| 19 | +EMBEDDING_STRUCT = pa.struct(_embedding_fields) |
| 20 | +EMBEDDING_SCHEMA = pa.schema(_embedding_fields) |
| 21 | +# END: Extension since v1.3 |
| 22 | + |
| 23 | +# BEGIN: Extension since v1.2 |
| 24 | +_text_fields = [ |
| 25 | + pa.field(name="confidence", type=pa.float16()), |
| 26 | + pa.field(name="text", type=pa.string()), |
| 27 | + pa.field(name="category", type=pa.dictionary(pa.int32(), pa.string())), |
| 28 | +] |
| 29 | +TEXT_STRUCT = pa.struct(_text_fields) |
| 30 | +TEXT_SCHEMA = pa.schema(_text_fields) |
| 31 | +# END: Extension since v1.2 |
| 32 | + |
| 33 | +# BEGIN: Extension since v1.1 |
| 34 | +_key_point_fields = [ |
| 35 | + pa.field(name="classLabel", type=pa.dictionary(pa.int32(), pa.string())), |
| 36 | + pa.field(name="confidence", type=pa.float16()), |
| 37 | + pa.field(name="x", type=pa.float16()), |
| 38 | + pa.field(name="y", type=pa.float16()), |
| 39 | + # optional z coordinate in pixel coordinate system, null="unknown" |
| 40 | + pa.field(name="z", type=pa.float16()), |
| 41 | + #optional flag true=visible, false=invisible, null="unknown" |
| 42 | + pa.field(name="visible", type=pa.bool_()), |
| 43 | + # BEGIN: Extension since v1.2 |
| 44 | + pa.field(name="category", type=pa.dictionary(pa.int32(), pa.string())), |
| 45 | + # END: Extension since v1.2 |
| 46 | +] |
| 47 | +KEY_POINT_STRUCT = pa.struct(_key_point_fields) |
| 48 | +KEY_POINT_SCHEMA = pa.schema(_key_point_fields) |
| 49 | +_key_points_fields = [ |
| 50 | + # optional |
| 51 | + pa.field(name="type", type=pa.dictionary(pa.int32(), pa.string())), |
| 52 | + pa.field(name="points", type=pa.list_(KEY_POINT_STRUCT)), |
| 53 | + # BEGIN: Extension since v1.2 |
| 54 | + pa.field(name="category", type=pa.dictionary(pa.int32(), pa.string())), |
| 55 | + # END: Extension since v1.2 |
| 56 | +] |
| 57 | +KEY_POINTS_STRUCT = pa.struct(_key_points_fields) |
| 58 | +KEY_POINTS_SCHEMA = pa.schema(_key_points_fields) |
| 59 | +# END: Extension since v1.1 |
| 60 | + |
| 61 | +_object_fields = [ |
| 62 | + pa.field(name="classLabel", type=pa.dictionary(pa.int32(), pa.string())), |
| 63 | + pa.field(name="confidence", type=pa.float16()), |
| 64 | + pa.field(name="x", type=pa.float16()), |
| 65 | + pa.field(name="y", type=pa.float16()), |
| 66 | + pa.field(name="width", type=pa.float16()), |
| 67 | + pa.field(name="height", type=pa.float16()), |
| 68 | + # from eyepop.data.data_types import UserReview |
| 69 | + pa.field(name="user_review", type=pa.dictionary(pa.int8(), pa.string())), |
| 70 | + # BEGIN: Extension since v1.1 |
| 71 | + pa.field(name="keyPoints", type=pa.list_(KEY_POINTS_STRUCT)), |
| 72 | + # END: Extension since v1.1 |
| 73 | + # BEGIN: Extension since v1.2 |
| 74 | + pa.field(name="category", type=pa.dictionary(pa.int32(), pa.string())), |
| 75 | + pa.field(name="texts", type=pa.list_(TEXT_STRUCT)), |
| 76 | + # END: Extension since v1.2 |
| 77 | +] |
| 78 | + |
| 79 | +OBJECT_STRUCT = pa.struct(_object_fields) |
| 80 | +OBJECT_SCHEMA = pa.schema(_object_fields) |
| 81 | + |
| 82 | +_class_fields = [ |
| 83 | + pa.field(name="classLabel", type=pa.dictionary(pa.int32(), pa.string())), |
| 84 | + pa.field(name="confidence", type=pa.float16()), |
| 85 | + # from eyepop.data.data_types import UserReview |
| 86 | + pa.field(name="user_review", type=pa.dictionary(pa.int8(), pa.string())), |
| 87 | + # BEGIN: Extension since v1.2 |
| 88 | + pa.field(name="category", type=pa.dictionary(pa.int32(), pa.string())), |
| 89 | + # END: Extension since v1.2 |
| 90 | +] |
| 91 | + |
| 92 | +CLASS_STRUCT = pa.struct(_class_fields) |
| 93 | +CLASS_SCHEMA = pa.schema(_class_fields) |
| 94 | + |
| 95 | +_annotation_fields = [ |
| 96 | + # from eyepop.data.data_types import AnnotationType |
| 97 | + pa.field(name="type", type=pa.dictionary(pa.int8(), pa.string())), |
| 98 | + # from eyepop.data.data_types import AutoAnnotate |
| 99 | + pa.field(name="source", type=pa.dictionary(pa.int32(), pa.string())), |
| 100 | + # from eyepop.data.data_types import UserReview |
| 101 | + pa.field(name="user_review", type=pa.dictionary(pa.int8(), pa.string())), |
| 102 | + pa.field(name="objects", type=pa.list_(OBJECT_STRUCT)), |
| 103 | + pa.field(name="classes", type=pa.list_(CLASS_STRUCT)), |
| 104 | + # read/write, optional, the model that produced this annotation |
| 105 | + pa.field(name="source_model_uuid", type=pa.dictionary(pa.int8(), pa.string())), |
| 106 | + # BEGIN: Extension since v1.1 |
| 107 | + pa.field(name="keyPoints", type=pa.list_(KEY_POINTS_STRUCT)), |
| 108 | + # END: Extension since v1.1 |
| 109 | + # BEGIN: Extension since v1.2 |
| 110 | + pa.field(name="texts", type=pa.list_(TEXT_STRUCT)), |
| 111 | + # END: Extension since v1.2 |
| 112 | + # BEGIN: Extension since v1.3 |
| 113 | + pa.field(name="embeddings", type=pa.list_(EMBEDDING_STRUCT)), |
| 114 | + # END: Extension since v1.3 |
| 115 | + # BEGIN: Extension since v1.4 |
| 116 | + pa.field(name="timestamp", type=pa.int64()), |
| 117 | + pa.field(name="duration", type=pa.int64()), |
| 118 | + pa.field(name="offset", type=pa.int64()), |
| 119 | + pa.field(name="offset_duration", type=pa.int64()), |
| 120 | + # END: Extension since v1.4 |
| 121 | +] |
| 122 | + |
| 123 | +ANNOTATION_STRUCT = pa.struct(_annotation_fields) |
| 124 | + |
| 125 | +ANNOTATION_SCHEMA = pa.schema(_annotation_fields) |
| 126 | + |
| 127 | +_asset_fields = [ |
| 128 | + pa.field(name="uuid", type=pa.string()), |
| 129 | + pa.field(name="external_id", type=pa.string()), |
| 130 | + pa.field(name="created_at", type=pa.timestamp("ms")), |
| 131 | + pa.field(name="updated_at", type=pa.timestamp("ms")), |
| 132 | + pa.field(name="asset_url", type=pa.string()), |
| 133 | + pa.field(name="original_image_width", type=pa.uint16()), |
| 134 | + pa.field(name="original_image_height", type=pa.uint16()), |
| 135 | + pa.field(name="partition", type=pa.dictionary(pa.int32(), pa.string())), |
| 136 | + pa.field(name="review_priority", type=pa.float16()), |
| 137 | + pa.field(name="model_relevance", type=pa.float16()), |
| 138 | + pa.field(name="annotations", type=pa.list_(ANNOTATION_STRUCT)), |
| 139 | +] |
| 140 | + |
| 141 | +ASSET_STRUCT = pa.struct(_asset_fields) |
| 142 | + |
| 143 | +ASSET_SCHEMA = pa.schema(_asset_fields) |
0 commit comments