{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/media/ppak/Storage/HuggingFace/Datasets/Melt-Pool-Thermal-Images/venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "import numpy as np\n", "import os\n", "import pickle\n", "import re\n", "\n", "from datasets import Dataset, concatenate_datasets\n", "from tqdm import tqdm" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "data_dir = \"../../NIST-In-Situ-IN625-LPBF-Overhangs/layer/base/\"" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def numerical_sort(value):\n", " # Extract numerical part from the string\n", " numbers = re.compile(r'(\\d+)')\n", " parts = numbers.split(value)\n", " parts[1::2] = map(int, parts[1::2])\n", " return parts" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 99/99 [03:09<00:00, 1.91s/it]\n" ] } ], "source": [ "dataset = None\n", "layer_frames_list = []\n", "# for layer_file in sorted(os.listdir(data_dir), key=numerical_sort)[0:2]:\n", "for layer_file in tqdm(sorted(os.listdir(data_dir), key=numerical_sort)):\n", " with open(f\"{data_dir}/{layer_file}\", \"rb\") as f:\n", " layer = pickle.load(f)\n", "\n", " # Transpose specific layer values\n", " layer_transposed = {}\n", " for key, value in layer.items():\n", " if (key in [\"build_time\", \"raw_frame_number\"]):\n", " # print(key, value.shape)\n", " value_transposed = value.transpose(1, 0)\n", " # print(key, value_transposed.shape)\n", " if (key == \"raw_frame_number\"):\n", " layer_transposed[key] = value_transposed.flatten()\n", " else:\n", " layer_transposed[key] = value_transposed\n", " elif (key == \"resolution\"):\n", " # print(key, value)\n", " value_flatten = value.flatten()\n", " # print(key, value_flatten)\n", " layer_transposed[key] = value_flatten\n", " else:\n", " layer_transposed[key] = value\n", "\n", " frames_list = []\n", " for frame_index, frame in enumerate(layer_transposed[\"radiant_temp\"]):\n", " frame_dict = {}\n", " frame_dict[\"frame_index\"] = frame_index\n", " for key, value in layer_transposed.items():\n", " if (key in [\"radiant_temp\", \"build_time\", \"raw_frame_number\"]):\n", " frame_dict[key] = value[frame_index]\n", " else:\n", " frame_dict[key] = value\n", " \n", " frames_list.append(frame_dict)\n", " \n", " layer_dataset = Dataset.from_list(frames_list)\n", " if dataset == None:\n", " dataset = layer_dataset\n", " else:\n", " dataset = concatenate_datasets([dataset, layer_dataset])\n", "\n", " # layer_frames_list += frames_list" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.25s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.18s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.25s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.30s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:08<00:00, 1.34s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:06<00:00, 1.10s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:09<00:00, 1.52s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.32s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:06<00:00, 1.03s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:06<00:00, 1.04s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.25s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.22s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:08<00:00, 1.45s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:10<00:00, 1.71s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.17s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:08<00:00, 1.37s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.26s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:08<00:00, 1.46s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:06<00:00, 1.08s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.32s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:09<00:00, 1.61s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:08<00:00, 1.37s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.28s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:08<00:00, 1.43s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:09<00:00, 1.65s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:08<00:00, 1.49s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:09<00:00, 1.57s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:06<00:00, 1.12s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.25s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.31s/ba]\n", "Creating parquet from Arrow format: 100%|██████████| 6/6 [00:07<00:00, 1.18s/ba]\n", "Uploading the dataset shards: 100%|██████████| 31/31 [05:00<00:00, 9.70s/it]\n" ] }, { "data": { "text/plain": [ "CommitInfo(commit_url='https://huggingface.co/datasets/ppak10/Melt-Pool-Thermal-Images/commit/3252ef78aceb07c7bbea05c43eda0f5c7070f869', commit_message='Upload dataset', commit_description='', oid='3252ef78aceb07c7bbea05c43eda0f5c7070f869', pr_url=None, pr_revision=None, pr_num=None)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dataset.push_to_hub(\n", " \"ppak10/Melt-Pool-Thermal-Images\",\n", " config_name = \"nist_overhangs_base_frame_data\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }