组合app

This commit is contained in:
somunslotus 2024-08-02 17:10:06 +08:00
parent 02009a8e52
commit 516f90406d
12 changed files with 237 additions and 9 deletions

View File

@ -24,6 +24,7 @@ smov_class_dict = {
1: 'Mo', 1: 'Mo',
2: 'V' 2: 'V'
} }
norm_line_sv_label = "点线缺陷分类" norm_line_sv_label = "点线缺陷分类"
cz_label = "正常掺杂分类" cz_label = "正常掺杂分类"
xj_label = "012三种不同结构的原子类型分类" xj_label = "012三种不同结构的原子类型分类"
@ -33,5 +34,26 @@ model_path_dict = {
cz_label: "model/cz_new.ckpt", cz_label: "model/cz_new.ckpt",
xj_label: "model/xj_new_2.ckpt", xj_label: "model/xj_new_2.ckpt",
smov_label: "model/smov.ckpt" smov_label: "model/smov.ckpt"
} }
from dataclasses import dataclass
from typing import List, Dict
@dataclass
class ModelLabel:
name: str
label: List[int]
import numpy as np
if __name__ == '__main__':
select_point_index = [2, 4]
AA =[0, 2, 4]
# 创建一个 Person 实例
tmp = np.isin(AA, select_point_index) # 返回 array([False, True, True])
atmp = ~np.isin(AA, select_point_index) # 返回 array([True, False, False])
BB = AA[atmp] # 返回 array([0])
print(BB)

BIN
egnn_v2/myplot46.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
egnn_v2/myplot49.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 KiB

View File

@ -10,21 +10,24 @@ from tqdm import tqdm
from PIL import Image from PIL import Image
from egnn_core.data import load_data from egnn_core.data import load_data
from egnn_core.data import load_data_v2 from egnn_core.data import load_data_v2
from model_type_dict import ModelLabel
from sklearn.metrics import accuracy_score, f1_score, recall_score, precision_score, confusion_matrix from sklearn.metrics import accuracy_score, f1_score, recall_score, precision_score, confusion_matrix
from typing import Dict, List
#需要支持不同的size,不止2048
def plot1(json_path, output_path, psize=24, img_size=2048): #img.shape 参数
bg = np.zeros((img_size, img_size)) + 255 def plot1(json_path, output_path, psize=24, img=None):
bg = np.zeros(img.shape, np.uint8) + 255
bg[0, 0] = 0 bg[0, 0] = 0
points, edge_index, labels, _ = load_data(json_path) points, edge_index, labels, _ = load_data(json_path)
mask_pd = np.zeros((img_size, img_size)) mask_pd = np.zeros(img.shape)
mask_pd[points[:, 0], points[:, 1]] = 1 mask_pd[points[:, 0], points[:, 1]] = 1
mask_pd = np.array(mask_pd, np.uint8) mask_pd = np.array(mask_pd, np.uint8)
plt.figure(figsize=(9, 9)) plt.figure(figsize=(9, 9))
plt.imshow(bg, cmap='gray') plt.imshow(img, cmap='gray')
h, w = np.where(mask_pd != 0) h, w = np.where(mask_pd != 0)
plt.scatter(points[:, 1], points[:, 0], s=16, c='#8EB9D9', zorder=2) plt.scatter(points[:, 1], points[:, 0], s=16, c='#8EB9D9', zorder=2)
@ -139,10 +142,84 @@ def plot_multiple_annotations(img_folder, json_folders, psize=26, output_folder=
plt.savefig(output_path, dpi=300) plt.savefig(output_path, dpi=300)
plt.close() plt.close()
def plot_arange_combine(img_folder, json_folders: Dict[str, str], select_labels:List[ModelLabel], output_folder: str, psize=40)->None:
# 确保输出文件夹存在
if not os.path.exists(output_folder):
os.makedirs(output_folder, exist_ok=True)
c = [
['#FF5733', '#33FF57', '#3357FF'], # Red, Green, Blue
['#FF33FF', '#33FFFF', '#FFFF33'], # Magenta, Cyan, Yellow
['#F08080', '#90EE90', '#ADD8E6'], # Light Coral, Light Green, Light Blue
['#FFD700', '#8A2BE2', '#FF4500'] # Gold, Blue Violet, Orange Red
]
# 遍历指定文件夹中的所有文件
for img_filename in os.listdir(img_folder):
plt.figure(figsize=(9, 9))
if img_filename.endswith(".jpg"): # 确保是jpeg文件
img_path = os.path.join(img_folder, img_filename)
img = cv2.imread(img_path, 0)
base_points_indexs = []
for i, select_label in enumerate(select_labels):
# 获取json文件
json_path = os.path.join(json_folders[select_label.name], os.path.splitext(os.path.basename(img_filename))[0] + '.json')
points, edge_index, labels, _ = load_data_v2(json_path)
# 第一个要特殊处理,要把全部标签点都画出来
if i == 0:
# 获取基础标签,可能有多个,所以用数组
for j, label in enumerate(select_label.label):
select_point_index = np.where(labels == select_label.label[j])[0]
base_points_indexs.append(select_point_index)
mask_pd = np.zeros(img.shape, np.uint8)
mask_pd[points[:, 0], points[:, 1]] = labels + 1
mask_pd = np.array(mask_pd, np.uint8)
for q in range(3):
h, w = np.where(mask_pd == q + 1)
plt.scatter(w, h, s=psize, c=c[i][q])
else:
model_label_index = []
# 获取用户选择的标签对应的点
for k, sub_select_label in enumerate(select_label.label):
tmp = np.where(labels == sub_select_label)[0]
model_label_index.append(tmp)
# 计算补集,去除基础标签的点
for index in model_label_index:
indexs = []
for base_points_index in base_points_indexs:
index = index[~np.isin(index, base_points_index)]
indexs.append(index)
for index in indexs:
labelsv = labels[index]
pointsv = points[index]
mask_pd = np.zeros(img.shape, np.uint8)
mask_pd[pointsv[:, 0], pointsv[:, 1]] = labelsv + 1
mask_pd = np.array(mask_pd, np.uint8)
for q in range(3):
h, w = np.where(mask_pd == q + 1)
plt.scatter(w, h, s=psize, c=c[i][q])
plt.imshow(img, cmap='gray')
plt.axis('off')
plt.tight_layout()
plt.savefig('kw.jpg', dpi=300)
plt.show()
#需求:根据用户筛选的标签,画出对应的图像
def plot_combine(img_path, json_path, json_path2, json_path3, json_path4, psize=40): def plot_combine(img_path, json_path, json_path2, json_path3, json_path4, psize=40):
c = ['#dfc8a0', '#814d81', '#debd97'] c = ['#dfc8a0', '#814d81', '#debd97']
##814d81紫色 ##814d81紫色
#根据预测结果获取标签
points, edge_index, labels, _ = load_data_v2(json_path) points, edge_index, labels, _ = load_data_v2(json_path)
img = cv2.imread(img_path, 0) img = cv2.imread(img_path, 0)
select_point_index = np.where(labels == 1)[0] select_point_index = np.where(labels == 1)[0]
@ -291,9 +368,30 @@ if __name__ == '__main__':
'/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/012三种不同结构的原子类型分类/gnn_predict_post_process/49.json', '/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/012三种不同结构的原子类型分类/gnn_predict_post_process/49.json',
'' ''
] ]
new_json_folder = [
'/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/012三种不同结构的原子类型分类/gnn_predict_post_process/49.json',
'/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/SMoV三种原子分类/gnn_predict_post_process/49.json',
'/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/正常掺杂分类/gnn_predict_post_process/49.json',
''
]
dict_json_folder = {
"正常掺杂分类": '/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/正常掺杂分类/gnn_predict_post_process',
"SMoV三种原子分类": '/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/SMoV三种原子分类/gnn_predict_post_process',
"012三种不同结构的原子类型分类": '/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/012三种不同结构的原子类型分类/gnn_predict_post_process',
}
select_labels = [
ModelLabel(name="012三种不同结构的原子类型分类", label=[1]),
ModelLabel(name="SMoV三种原子分类", label=[0,1]),
ModelLabel(name="正常掺杂分类", label=[1]),
]
plot_arange_combine(folder, dict_json_folder, select_labels=select_labels, output_folder='/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/combine_view_0731')
#plot2(folder, folder) #plot2(folder, folder)
plot_combine(img_folder, json_folders[0], json_folders[1], json_folders[2], json_folders[3]) #plot_combine(img_folder, new_json_folder[0], new_json_folder[1], new_json_folder[2], new_json_folder[3])
#plot_multiple_annotations(img_folder, json_folders, output_folder='/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/combine_view') #plot_multiple_annotations(img_folder, json_folders, output_folder='/home/deploy/script/bohrim-app/bohrium-app/pythonProject/msunet/result_combine_3/combine_view')
except Exception as e: except Exception as e:
import traceback import traceback
print(f"Error processing error: {e}") print(f"Error processing error: {e}")

View File

@ -0,0 +1,108 @@
import os
import cv2
import glob
import json
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from tqdm import tqdm
from PIL import Image
from core.data import load_data_v2_plot,load_data_v2_plot_jj
from sklearn.metrics import accuracy_score, f1_score, recall_score, precision_score, confusion_matrix
def plot1(json_path, psize=24, img_size=2048):
bg = np.zeros((img_size, img_size)) + 255
bg[0, 0] = 0
points, edge_index, labels, _ = load_data_v2_plot(json_path,max_edge_length=28)
mask_pd = np.zeros((img_size, img_size))
mask_pd[points[:, 0], points[:, 1]] = 1
mask_pd = np.array(mask_pd, np.uint8)
plt.figure(figsize=(9, 9))
plt.imshow(bg, cmap='gray')
h, w = np.where(mask_pd != 0)
plt.scatter(points[:, 1], points[:, 0], s=16, c='#8EB9D9', zorder=2)
#
for idx, (s, e) in enumerate(edge_index.T):
s = points[s]
e = points[e]
plt.plot([s[1], e[1]], [s[0], e[0]], linewidth=1, c='#C0C0C0', zorder=1)
plt.axis('off')
plt.tight_layout()
def plot2(img_path, json_path, psize=40):
# c = ['#84aad0', '#84aad0', '#84aad0']
c = [ '#dfc8a0', '#84aad0','#93ba66']
# c = [ '#dfc8a0','#debd97', '#84aad0']
# c = ['#9BB6CF', '#9BB6CF', '#9BB6CF']
# c = ['#83a2c1', '#9BB6CF', '#9BB6CF']
img = cv2.imread(img_path, 0)
# points, edge_index, labels, _ = load_data_v2_plot(json_path,max_edge_length=25)
points, edge_index, labels, _ = load_data_v2_plot(json_path,max_edge_length=28)
# points, edge_index, labels, _ = load_data_v2_plot_jj(json_path,max_edge_length=31)
mask_pd = np.zeros(img.shape)
# mask_pd = np.zeros((512, 512)) + 256
# mask_pd = np.zeros((w, h)) + 256
mask_pd[points[:, 0], points[:, 1]] = labels + 1
mask_pd = np.array(mask_pd, np.uint8)
plt.figure(figsize=(9, 9))
plt.imshow(img, cmap='gray')
# img = np.array(Image.open(img_path))
# bg = np.zeros_like(img) + 255
# bg[0, 0] = 0
# plt.imshow(bg, cmap='gray')
for idx, (s, e) in enumerate(edge_index.T):
s = points[s]
e = points[e]
plt.plot([s[1], e[1]], [s[0], e[0]], linewidth=1, c='#C0C0C0', zorder=1)
for i in range(3):
h, w = np.where(mask_pd == i + 1)
plt.scatter(w, h, s=psize, c=c[i])
plt.axis('off')
plt.tight_layout()
plt.savefig('2.jpg',dpi=300)
plt.show()
# json_path = '/home/gao/mouclear/cc/data/end-to-end-result-xj/xj_gnn/train/raw/train1.json'
# img_path = '/home/gao/mouclear/cc/data/end-to-end-result-xj/xj_gnn/train/raw/train1.jpg'
# json_path = '/home/gao/mouclear/cc/data/e2e-xj-adjust/xj-adjust/atom/test-5.json'
# img_path = '/home/gao/mouclear/cc/data/e2e-xj-adjust/xj-adjust/atom/test-5.jpg'
# json_path = '/home/gao/mouclear/cc/data/e2e_xj_final/xj_result/raw/test.json'
# img_path = '/home/gao/mouclear/cc/data/e2e_xj_final/xj_result/raw/test.jpg'
# json_path = '/home/gao/mouclear/cc/data/e2e_xj_final/atom/test.json'
# img_path = '/home/gao/mouclear/cc/data/e2e_xj_final/atom/test.jpg'a,m,,,,,
# json_path = '/home/gao/mouclear/cc/code/pd_2/data/gnn_vor/train/raw/1.json'
# img_path = '/home/gao/mouclear/cc/code/pd_2/data/gnn_vor/train/raw/1.jpg'
json_path = '/home/gao/mouclear/cc/final_todo/fig_50/53-1/xj/after_norm/53-1.json'
img_path = '/home/gao/mouclear/cc/final_todo/fig_50/53-1/xj/after_norm/53-1.jpg'
# json_path = '/home/gao/mouclear/cc/data/e2e-xj-adjust/xj-adjust/atom/another/test.json'
# img_path = '/home/gao/mouclear/cc/data/e2e-xj-adjust/xj-adjust/atom/another/test.jpg'
# json_path = '/home/gao/mouclear/cc/data/edge/point-2.json'
# img_path = '/home/gao/mouclear/cc/data/edge/point-2.jpg'
# json_path = '/home/gao/mouclear/cc/data/end-to-end-result-xj/end-to-end-gnn/raw/test.json'
# img_path = '/home/gao/mouclear/cc/data/end-to-end-result-xj/end-to-end-gnn/raw/test.jpg'
# # json_path = '/home/gao/mouclear/cc/data/end-to-end-result-xj/end-to-end-gnn/gt/test.json'
# img_path = '/home/gao/mouclear/cc/data/end-to-end-result-xj/end-to-end-gnn/gt/test.jpg'
plot2(img_path, json_path)
# plot(img_path, json_path)

View File

@ -81,8 +81,8 @@ class CombineGnnPredictOptions(BaseModel):
select_models: List[SingleWrapper] = Field(default=[SingleWrapper(model_name=norm_line_sv_label)],min_items=1, unique_items=True, description="选择的模型") select_models: List[SingleWrapper] = Field(default=[SingleWrapper(model_name=norm_line_sv_label)],min_items=1, unique_items=True, description="选择的模型")
edges_length: Float = Field(default=35.5, description="连接节点边长") edges_length: Float = Field(default=35.5, description="连接节点边长")
data_path: InputFilePath = Field(..., ftypes=['zip'], description="测试的数据集") data_path: InputFilePath = Field(..., ftypes=['zip'], description="测试的数据集")
model_path: Optional[InputFilePath] = Field(ftypes=['ckpt'], description="原子缺陷检测模型") #model_path: Optional[InputFilePath] = Field(ftypes=['ckpt'], description="原子缺陷检测模型")
gnn_model_path: Optional[InputFilePath] = Field(ftypes=['ckpt'], description="gnn模型") #gnn_model_path: Optional[InputFilePath] = Field(ftypes=['ckpt'], description="gnn模型")
output_dir: OutputDirectory = Field( output_dir: OutputDirectory = Field(
default="./result" default="./result"
) # default will be override after online ) # default will be override after online

Binary file not shown.

Before

Width:  |  Height:  |  Size: 596 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 596 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 596 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 KiB