{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/ppak/HuggingFace/Datasets/Melt-Pool-Thermal-Images/venv/lib/python3.8/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": 6,
"metadata": {},
"outputs": [],
"source": [
"data_dir = \"../../NIST-In-Situ-IN625-LPBF-Overhangs/layer\"\n",
"folders = [\"base\", \"overhang_with_supports\", \"block\", \"overhang_no_supports\"]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"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": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"base\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 99/99 [01:28<00:00, 1.12it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"overhang_with_supports\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 180/180 [01:31<00:00, 1.97it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"block\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 100/100 [01:33<00:00, 1.07it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"overhang_no_supports\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 179/179 [01:58<00:00, 1.51it/s]\n"
]
}
],
"source": [
"dataset = None\n",
"for folder in folders:\n",
" print(folder)\n",
" folder_dir = f\"{data_dir}/{folder}/\"\n",
" for layer_file in tqdm(sorted(os.listdir(folder_dir), key=numerical_sort)):\n",
" with open(f\"{folder_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])"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.77ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.85ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.93ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.89ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.89ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.88ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.84ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.88ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.83ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.81ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.83ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.83ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.90ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.90ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.85ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.86ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.88ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.85ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.87ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.90ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.86ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.90ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.93ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.94ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.89ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:02<00:00, 2.01ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.90ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.77ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.89ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.77ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.99ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.97ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:02<00:00, 2.04ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:02<00:00, 2.00ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.90ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.86ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.89ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.83ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.86ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.78ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.81ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.83ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.95ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.80ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.80ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.72ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.77ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.80ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.78ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.74ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.80ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.78ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.85ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.78ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.80ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.77ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.86ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.78ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.73ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.81ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.79ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.90ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.79ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.88ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.92ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.83ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.84ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.86ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.85ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.87ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.84ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.79ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.76ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.88ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.84ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.93ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.88ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.83ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.91ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.85ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.81ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.78ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.94ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.90ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.81ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.78ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.87ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.85ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.73ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.83ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.75ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.68ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.86ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.84ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.73ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.82ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.69ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.65ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.82ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.81ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.72ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.76ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.84ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.63ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.70ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.70ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.59ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.76ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.76ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.70ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.70ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.82ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.74ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.64ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.57ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.57ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.70ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:04<00:00, 1.46ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.69ba/s]\n",
"Creating parquet from Arrow format: 100%|██████████| 6/6 [00:03<00:00, 1.62ba/s]\n",
"Uploading the dataset shards: 100%|██████████| 130/130 [07:40<00:00, 3.54s/it]\n"
]
},
{
"data": {
"text/plain": [
"CommitInfo(commit_url='https://huggingface.co/datasets/ppak10/Melt-Pool-Thermal-Images/commit/53f0639953b72bfaa6f4a2a472de2fc85e63b4a5', commit_message='Upload dataset (part 00002-of-00003)', commit_description='', oid='53f0639953b72bfaa6f4a2a472de2fc85e63b4a5', pr_url=None, pr_revision=None, pr_num=None)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
"\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
"\u001b[1;31mClick here for more info. \n",
"\u001b[1;31mView Jupyter log for further details."
]
}
],
"source": [
"dataset.push_to_hub(\n",
" \"ppak10/Melt-Pool-Thermal-Images\",\n",
" config_name = \"NIST_overhang_frames\",\n",
" split = \"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}