atom-predict/msunet/.ipynb_checkpoints/WL-checkpoint.ipynb

128 lines
2.7 KiB
Plaintext
Executable File

{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"id": "0451eb90-6a57-40b5-836d-153b4f1d08f1",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import json\n",
"import glob\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from PIL import Image\n",
"from utils.pesudo import load_data, get_y_3"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "90798480-e2e7-4b9f-8d45-25339df1ee0d",
"metadata": {},
"outputs": [],
"source": [
"_dict = {\n",
" 0: 'Norm',\n",
" 1: 'LineSV',\n",
" 2: 'SV'\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d1ee59e7-b42f-488c-86ab-452071f35ca9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"json_lst = glob.glob('./03/raw/*.json', recursive=True); len(json_lst)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "fa258b0e-cee4-46d4-b03b-3c8e337db095",
"metadata": {},
"outputs": [],
"source": [
"thres = 160"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "aafe6474-d19a-4def-963c-cb34a85b5bbd",
"metadata": {},
"outputs": [],
"source": [
"for json_path in json_lst:\n",
" base_name = json_path.split('/')[-1]\n",
" points, edge_index, labels, lights = load_data(json_path)\n",
" labels = np.array([int(light < thres) for light in lights])\n",
" labels = get_y_3(labels, edge_index)\n",
"\n",
" with open(json_path) as f:\n",
" data = json.load(f)\n",
"\n",
" for i in range(len(data['shapes'])):\n",
" data['shapes'][i]['label'] = _dict[labels[i]]\n",
" \n",
" with open('./03/{}'.format(base_name), 'w') as f:\n",
" json.dump(data, f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7a319bd-9643-4eb5-83e7-09cab4925236",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "53f4bd55-fad8-4447-b06f-d71aee9f2c27",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "cmae",
"language": "python",
"name": "cmae"
},
"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.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}