Update README.md
Browse files
README.md
CHANGED
|
@@ -47,7 +47,7 @@ dataset_summary: >
|
|
| 47 |
|
| 48 |
# Note: other available arguments include 'max_samples', etc
|
| 49 |
|
| 50 |
-
dataset = load_from_hub("
|
| 51 |
|
| 52 |
|
| 53 |
# Launch the App
|
|
@@ -84,34 +84,70 @@ from huggingface_hub import snapshot_download
|
|
| 84 |
|
| 85 |
|
| 86 |
# Download the dataset snapshot to the current working directory
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
import fiftyone as fo
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
dataset = fo.Dataset.from_dir(
|
| 92 |
-
dataset_dir=".",
|
| 93 |
-
dataset_type=fo.types.FiftyOneDataset,
|
| 94 |
-
name="crops3d"
|
| 95 |
)
|
| 96 |
|
| 97 |
def update_dataset_ply_paths(dataset):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
for sample in dataset:
|
|
|
|
| 99 |
fo3d_filepath = sample.filepath
|
|
|
|
|
|
|
| 100 |
fo3d_directory = os.path.dirname(fo3d_filepath)
|
| 101 |
|
|
|
|
| 102 |
with open(fo3d_filepath, 'r') as f:
|
| 103 |
fo3d_data = json.load(f)
|
| 104 |
|
|
|
|
| 105 |
for child in fo3d_data.get('children', []):
|
|
|
|
| 106 |
if child.get('_type') == 'PlyMesh' and 'plyPath' in child:
|
|
|
|
|
|
|
| 107 |
child['plyPath'] = os.path.join(fo3d_directory, child['plyPath'])
|
| 108 |
|
|
|
|
| 109 |
with open(fo3d_filepath, 'w') as f:
|
| 110 |
-
json.dump(fo3d_data, f, indent=2)
|
| 111 |
|
| 112 |
-
#
|
| 113 |
update_dataset_ply_paths(dataset)
|
| 114 |
-
|
| 115 |
```
|
| 116 |
|
| 117 |
# Dataset Details
|
|
@@ -120,9 +156,9 @@ update_dataset_ply_paths(dataset)
|
|
| 120 |
|
| 121 |
**Curated by:** Jianzhong Zhu, Ruifang Zhai, He Ren, Kai Xie, Aobo Du, Xinwei He, Chenxi Cui, Yinghua Wang, Junli Ye, Jiashi Wang, Xue Jiang, Yulong Wang, Chenglong Huang, Wanneng Yang (Huazhong Agricultural University, China)
|
| 122 |
|
| 123 |
-
**Funded by
|
| 124 |
|
| 125 |
-
**Shared by
|
| 126 |
|
| 127 |
**Language(s) (NLP):** Not applicable (3D point cloud dataset)
|
| 128 |
|
|
|
|
| 47 |
|
| 48 |
# Note: other available arguments include 'max_samples', etc
|
| 49 |
|
| 50 |
+
dataset = load_from_hub("Voxel51/crops3d")
|
| 51 |
|
| 52 |
|
| 53 |
# Launch the App
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
# Download the dataset snapshot to the current working directory
|
| 87 |
+
|
| 88 |
+
snapshot_download(repo_id="Voxel51/crops3d", local_dir=".", repo_type="dataset")
|
| 89 |
|
| 90 |
import fiftyone as fo
|
| 91 |
|
| 92 |
+
import fiftyone as fo
|
| 93 |
+
import os
|
| 94 |
+
import json
|
| 95 |
+
|
| 96 |
+
# Load dataset from current directory using FiftyOne's native format
|
| 97 |
dataset = fo.Dataset.from_dir(
|
| 98 |
+
dataset_dir=".", # Current directory contains the dataset files
|
| 99 |
+
dataset_type=fo.types.FiftyOneDataset, # Specify FiftyOne dataset format
|
| 100 |
+
name="crops3d" # Assign a name to the dataset for identification
|
| 101 |
)
|
| 102 |
|
| 103 |
def update_dataset_ply_paths(dataset):
|
| 104 |
+
"""
|
| 105 |
+
Update PLY file paths in FiftyOne 3D dataset to use absolute paths.
|
| 106 |
+
|
| 107 |
+
This function iterates through all samples in a FiftyOne dataset and modifies
|
| 108 |
+
any PLY mesh file paths found in the JSON metadata to be absolute paths
|
| 109 |
+
relative to the sample's directory location.
|
| 110 |
+
|
| 111 |
+
Args:
|
| 112 |
+
dataset (fiftyone.Dataset): A FiftyOne dataset containing 3D samples
|
| 113 |
+
with JSON metadata files that may reference
|
| 114 |
+
PLY mesh files with relative paths.
|
| 115 |
+
|
| 116 |
+
Returns:
|
| 117 |
+
None: The function modifies the JSON files in-place on disk.
|
| 118 |
+
|
| 119 |
+
Note:
|
| 120 |
+
- This function assumes each sample's filepath points to a JSON file
|
| 121 |
+
- The JSON structure should contain a 'children' array with objects
|
| 122 |
+
- PLY mesh objects are identified by '_type': 'PlyMesh'
|
| 123 |
+
- Only objects with a 'plyPath' field will be updated
|
| 124 |
+
"""
|
| 125 |
+
# Iterate through each sample in the dataset
|
| 126 |
for sample in dataset:
|
| 127 |
+
# Get the file path of the current sample (JSON metadata file)
|
| 128 |
fo3d_filepath = sample.filepath
|
| 129 |
+
|
| 130 |
+
# Extract the directory containing the sample file
|
| 131 |
fo3d_directory = os.path.dirname(fo3d_filepath)
|
| 132 |
|
| 133 |
+
# Read and parse the JSON metadata file
|
| 134 |
with open(fo3d_filepath, 'r') as f:
|
| 135 |
fo3d_data = json.load(f)
|
| 136 |
|
| 137 |
+
# Process each child object in the JSON structure
|
| 138 |
for child in fo3d_data.get('children', []):
|
| 139 |
+
# Check if this child is a PLY mesh object with a path reference
|
| 140 |
if child.get('_type') == 'PlyMesh' and 'plyPath' in child:
|
| 141 |
+
# Convert relative PLY path to absolute path
|
| 142 |
+
# by joining it with the sample's directory
|
| 143 |
child['plyPath'] = os.path.join(fo3d_directory, child['plyPath'])
|
| 144 |
|
| 145 |
+
# Write the updated JSON data back to the file
|
| 146 |
with open(fo3d_filepath, 'w') as f:
|
| 147 |
+
json.dump(fo3d_data, f, indent=2) # Pretty-print with 2-space indentation
|
| 148 |
|
| 149 |
+
# Execute the path update function on the loaded dataset
|
| 150 |
update_dataset_ply_paths(dataset)
|
|
|
|
| 151 |
```
|
| 152 |
|
| 153 |
# Dataset Details
|
|
|
|
| 156 |
|
| 157 |
**Curated by:** Jianzhong Zhu, Ruifang Zhai, He Ren, Kai Xie, Aobo Du, Xinwei He, Chenxi Cui, Yinghua Wang, Junli Ye, Jiashi Wang, Xue Jiang, Yulong Wang, Chenglong Huang, Wanneng Yang (Huazhong Agricultural University, China)
|
| 158 |
|
| 159 |
+
**Funded by:** National Natural Science Foundation of China, National Key Research and Development Program of China
|
| 160 |
|
| 161 |
+
**Shared by:** Huazhong Agricultural University, National Key Laboratory of Crop Genetic Improvement
|
| 162 |
|
| 163 |
**Language(s) (NLP):** Not applicable (3D point cloud dataset)
|
| 164 |
|