DsL
commited on
Commit
·
7f66eeb
1
Parent(s):
6b911a1
update
Browse files- Causal3D_Dataset.py +1 -84
Causal3D_Dataset.py
CHANGED
@@ -86,12 +86,12 @@ class Causal3dDataset(datasets.GeneratorBasedBuilder):
|
|
86 |
]
|
87 |
|
88 |
def _generate_examples(self, data_dir):
|
89 |
-
print(f"Generating examples from: {data_dir}")
|
90 |
image_files = {}
|
91 |
for ext in ("*.png", "*.jpg", "*.jpeg"):
|
92 |
for img_path in Path(data_dir).rglob(ext):
|
93 |
relative = str(img_path.relative_to(data_dir))
|
94 |
image_files[relative] = str(img_path)
|
|
|
95 |
|
96 |
csv_files = [f for f in Path(data_dir).rglob("*.csv") if not f.name.startswith("._")]
|
97 |
df = pd.read_csv(csv_files[0]) if csv_files else None
|
@@ -118,86 +118,3 @@ class Causal3dDataset(datasets.GeneratorBasedBuilder):
|
|
118 |
"file_name": fname,
|
119 |
"metadata": None,
|
120 |
}
|
121 |
-
|
122 |
-
|
123 |
-
# def _generate_examples(self, data_dir):
|
124 |
-
# def color(text, code):
|
125 |
-
# return f"\033[{code}m{text}\033[0m"
|
126 |
-
# print("load data from {}".format(data_dir))
|
127 |
-
# try:
|
128 |
-
# image_files = {}
|
129 |
-
# for ext in ("*.png", "*.jpg", "*.jpeg"):
|
130 |
-
# for img_path in Path(data_dir).rglob(ext):
|
131 |
-
# relative_path = str(img_path.relative_to(data_dir))
|
132 |
-
# image_files[relative_path] = str(img_path)
|
133 |
-
# parts = [i.split('/')[0] for i in list(image_files.keys())]
|
134 |
-
# parts = set(parts)
|
135 |
-
# if "part_000" not in parts:
|
136 |
-
# parts= ['']
|
137 |
-
|
138 |
-
|
139 |
-
# except Exception as e:
|
140 |
-
# print(color(f"Error loading images: {e}", "31")) # Red
|
141 |
-
# return
|
142 |
-
|
143 |
-
# # Find the .csv file
|
144 |
-
# csv_files = [f for f in Path(data_dir).rglob("*.csv") if not f.name.startswith("._")]
|
145 |
-
# if not csv_files:
|
146 |
-
# # print(f"\033[33m[SKIP] No CSV found in {data_dir}, skipping this config.\033[0m")
|
147 |
-
# pass
|
148 |
-
# # print(f"\033[33m[INFO] Found CSV: {csv_files}\033[0m")
|
149 |
-
# csv_path = csv_files[0] if csv_files else None
|
150 |
-
# df = pd.read_csv(csv_path) if csv_path else None
|
151 |
-
# image_col_exists = True
|
152 |
-
# if df is not None and "imgs" not in df.columns:
|
153 |
-
# image_col_exists = False
|
154 |
-
|
155 |
-
# images = df["imgs"].tolist() if image_col_exists and df is not None else []
|
156 |
-
# images = [i.split('/')[-1].split('.')[0] for i in images if i.endswith(('.png', '.jpg', '.jpeg'))]
|
157 |
-
|
158 |
-
# try:
|
159 |
-
# # Match CSV rows with image paths
|
160 |
-
# if df is None:
|
161 |
-
# for i, j in tqdm(image_files.items(), desc="Processing images", unit="image"):
|
162 |
-
# yield i, {
|
163 |
-
# "image": j,
|
164 |
-
# "file_name": i,
|
165 |
-
# "metadata": None,
|
166 |
-
# }
|
167 |
-
|
168 |
-
# else:
|
169 |
-
# for idx, row in tqdm(df.iterrows(), total=len(df), desc="Processing rows", unit="row"):
|
170 |
-
# fname = row["imgs"]
|
171 |
-
# raw_record_img_path = row["imgs"] #images[idx] if images else "" #row["image"]
|
172 |
-
# record_img_name = raw_record_img_path.split('/')[-1]
|
173 |
-
# render_img_path = record_img_name
|
174 |
-
|
175 |
-
|
176 |
-
# # for part in parts:
|
177 |
-
# # if part == '':
|
178 |
-
# # record_img_path = record_img_name
|
179 |
-
# # else:
|
180 |
-
# # record_img_path = "/".join([part, record_img_name.strip()])
|
181 |
-
# # if "Water_flow_scene_render" in data_dir:
|
182 |
-
# # record_img_path = "/".join([part, str(int(record_img_name.strip().split('.')[0]))+".png"])
|
183 |
-
# # if record_img_path in image_files:
|
184 |
-
# # # print(color(f"record_img_path: { image_files[record_img_path]}", "34")) # Blue
|
185 |
-
# # yield idx, {
|
186 |
-
# # "image": image_files[record_img_path],
|
187 |
-
# # "file_name": fname,
|
188 |
-
# # "metadata": row.to_json(),
|
189 |
-
# # }
|
190 |
-
# # break
|
191 |
-
|
192 |
-
# # else:
|
193 |
-
# # yield idx, {
|
194 |
-
# # # "image": "",
|
195 |
-
# # "file_name": fname,
|
196 |
-
# # "metadata": row.to_json(),
|
197 |
-
# # }
|
198 |
-
# # break
|
199 |
-
|
200 |
-
|
201 |
-
# except Exception as e:
|
202 |
-
# print(color(f"Error processing CSV rows: {e}", "31"))
|
203 |
-
|
|
|
86 |
]
|
87 |
|
88 |
def _generate_examples(self, data_dir):
|
|
|
89 |
image_files = {}
|
90 |
for ext in ("*.png", "*.jpg", "*.jpeg"):
|
91 |
for img_path in Path(data_dir).rglob(ext):
|
92 |
relative = str(img_path.relative_to(data_dir))
|
93 |
image_files[relative] = str(img_path)
|
94 |
+
print(f"Found {len(image_files)} images in {data_dir}")
|
95 |
|
96 |
csv_files = [f for f in Path(data_dir).rglob("*.csv") if not f.name.startswith("._")]
|
97 |
df = pd.read_csv(csv_files[0]) if csv_files else None
|
|
|
118 |
"file_name": fname,
|
119 |
"metadata": None,
|
120 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|