更换模型路径

This commit is contained in:
FEIJINTI 2022-07-27 08:14:05 +08:00
parent f415a480a6
commit 5ace1f858b
3 changed files with 19 additions and 99 deletions

View File

@ -12,7 +12,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 3,
"outputs": [], "outputs": [],
"source": [ "source": [
"import numpy as np\n", "import numpy as np\n",
@ -30,7 +30,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 4,
"outputs": [], "outputs": [],
"source": [ "source": [
"train_from_existed = False # 是否从现有数据训练如果是的话那就从dataset_file训练否则就用data_dir里头的数据\n", "train_from_existed = False # 是否从现有数据训练如果是的话那就从dataset_file训练否则就用data_dir里头的数据\n",
@ -38,8 +38,8 @@
"dataset_file = \"data/dataset/dataset_2022-07-20_10-04.mat\"\n", "dataset_file = \"data/dataset/dataset_2022-07-20_10-04.mat\"\n",
"\n", "\n",
"# color_dict = {(0, 0, 255): \"yangeng\", (255, 0, 0): 'beijing',(0, 255, 0): \"zibian\"} # 颜色对应的类别\n", "# color_dict = {(0, 0, 255): \"yangeng\", (255, 0, 0): 'beijing',(0, 255, 0): \"zibian\"} # 颜色对应的类别\n",
"color_dict = {(0, 0, 255): \"yangeng\"}\n", "# color_dict = {(0, 0, 255): \"yangeng\"}\n",
"# color_dict = {(255, 0, 0): 'beijing'}\n", "color_dict = {(255, 0, 0): 'beijing'}\n",
"# color_dict = {(0, 255, 0): \"zibian\"}\n", "# color_dict = {(0, 255, 0): \"zibian\"}\n",
"label_index = {\"yangeng\": 1, \"beijing\": 0, \"zibian\":2} # 类别对应的序号\n", "label_index = {\"yangeng\": 1, \"beijing\": 0, \"zibian\":2} # 类别对应的序号\n",
"show_samples = False # 是否展示样本\n", "show_samples = False # 是否展示样本\n",
@ -70,7 +70,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 5,
"outputs": [], "outputs": [],
"source": [ "source": [
"dataset = read_labeled_img(data_dir, color_dict=color_dict, is_ps_color_space=False)\n", "dataset = read_labeled_img(data_dir, color_dict=color_dict, is_ps_color_space=False)\n",
@ -99,7 +99,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 6,
"outputs": [], "outputs": [],
"source": [ "source": [
"if len(dataset) > 1:\n", "if len(dataset) > 1:\n",
@ -130,7 +130,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 7,
"outputs": [], "outputs": [],
"source": [ "source": [
"# 对数据进行预处理\n", "# 对数据进行预处理\n",
@ -147,84 +147,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 8,
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n", "38411it [02:01, 316.59it/s] \n"
" 0%| | 0/9019 [00:00<?, ?it/s]\u001B[A\n",
" 1%|▊ | 128/9019 [00:00<00:06, 1270.70it/s]\u001B[A\n",
" 3%|█▋ | 256/9019 [00:00<00:06, 1256.08it/s]\u001B[A\n",
" 4%|██▍ | 383/9019 [00:00<00:06, 1258.22it/s]\u001B[A\n",
" 6%|███▎ | 509/9019 [00:00<00:06, 1255.32it/s]\u001B[A\n",
" 7%|████ | 635/9019 [00:00<00:06, 1249.27it/s]\u001B[A\n",
" 8%|████▉ | 760/9019 [00:00<00:06, 1225.89it/s]\u001B[A\n",
" 10%|█████▋ | 883/9019 [00:00<00:06, 1201.33it/s]\u001B[A\n",
" 11%|██████▎ | 1006/9019 [00:00<00:06, 1207.75it/s]\u001B[A\n",
" 13%|███████▏ | 1133/9019 [00:00<00:06, 1224.08it/s]\u001B[A\n",
" 14%|███████▉ | 1260/9019 [00:01<00:06, 1235.27it/s]\u001B[A\n",
" 15%|████████▊ | 1388/9019 [00:01<00:06, 1246.04it/s]\u001B[A\n",
" 17%|█████████▌ | 1517/9019 [00:01<00:05, 1256.50it/s]\u001B[A\n",
" 18%|██████████▍ | 1643/9019 [00:01<00:05, 1254.78it/s]\u001B[A\n",
" 20%|███████████▏ | 1771/9019 [00:01<00:05, 1259.58it/s]\u001B[A\n",
" 21%|███████████▉ | 1897/9019 [00:01<00:05, 1238.51it/s]\u001B[A\n",
" 22%|████████████▊ | 2029/9019 [00:01<00:05, 1259.90it/s]\u001B[A\n",
" 24%|█████████████▋ | 2156/9019 [00:01<00:05, 1252.72it/s]\u001B[A\n",
" 25%|██████████████▍ | 2284/9019 [00:01<00:05, 1258.07it/s]\u001B[A\n",
" 27%|███████████████▎ | 2414/9019 [00:01<00:05, 1267.77it/s]\u001B[A\n",
" 28%|████████████████ | 2543/9019 [00:02<00:05, 1271.61it/s]\u001B[A\n",
" 30%|████████████████▉ | 2671/9019 [00:02<00:05, 1248.75it/s]\u001B[A\n",
" 31%|█████████████████▋ | 2796/9019 [00:02<00:05, 1228.46it/s]\u001B[A\n",
" 32%|██████████████████▌ | 2928/9019 [00:02<00:04, 1252.55it/s]\u001B[A\n",
" 34%|███████████████████▎ | 3054/9019 [00:02<00:04, 1226.91it/s]\u001B[A\n",
" 35%|████████████████████ | 3184/9019 [00:02<00:04, 1245.55it/s]\u001B[A\n",
" 37%|████████████████████▉ | 3309/9019 [00:02<00:04, 1240.56it/s]\u001B[A\n",
" 38%|█████████████████████▋ | 3437/9019 [00:02<00:04, 1249.48it/s]\u001B[A\n",
" 40%|██████████████████████▌ | 3563/9019 [00:02<00:04, 1231.75it/s]\u001B[A\n",
" 41%|███████████████████████▎ | 3687/9019 [00:02<00:04, 1224.38it/s]\u001B[A\n",
" 42%|████████████████████████ | 3811/9019 [00:03<00:04, 1226.33it/s]\u001B[A\n",
" 44%|████████████████████████▉ | 3939/9019 [00:03<00:04, 1239.50it/s]\u001B[A\n",
" 45%|█████████████████████████▋ | 4064/9019 [00:03<00:04, 1214.87it/s]\u001B[A\n",
" 46%|██████████████████████████▍ | 4186/9019 [00:03<00:04, 1203.27it/s]\u001B[A\n",
" 48%|███████████████████████████▎ | 4316/9019 [00:03<00:03, 1228.92it/s]\u001B[A\n",
" 49%|████████████████████████████ | 4447/9019 [00:03<00:03, 1250.09it/s]\u001B[A\n",
" 51%|████████████████████████████▉ | 4576/9019 [00:03<00:03, 1259.16it/s]\u001B[A\n",
" 52%|█████████████████████████████▋ | 4703/9019 [00:03<00:03, 1223.56it/s]\u001B[A\n",
" 54%|██████████████████████████████▌ | 4835/9019 [00:03<00:03, 1248.96it/s]\u001B[A\n",
" 55%|███████████████████████████████▎ | 4964/9019 [00:03<00:03, 1258.30it/s]\u001B[A\n",
" 56%|████████████████████████████████▏ | 5091/9019 [00:04<00:03, 1189.27it/s]\u001B[A\n",
" 58%|████████████████████████████████▉ | 5211/9019 [00:04<00:03, 1186.49it/s]\u001B[A\n",
" 59%|█████████████████████████████████▊ | 5343/9019 [00:04<00:03, 1222.33it/s]\u001B[A\n",
" 61%|██████████████████████████████████▌ | 5466/9019 [00:04<00:02, 1221.71it/s]\u001B[A\n",
" 62%|███████████████████████████████████▎ | 5589/9019 [00:04<00:02, 1214.43it/s]\u001B[A\n",
" 63%|████████████████████████████████████ | 5714/9019 [00:04<00:02, 1222.25it/s]\u001B[A\n",
" 65%|████████████████████████████████████▉ | 5843/9019 [00:04<00:02, 1239.56it/s]\u001B[A\n",
" 66%|█████████████████████████████████████▋ | 5968/9019 [00:04<00:02, 1236.51it/s]\u001B[A\n",
" 68%|██████████████████████████████████████▌ | 6092/9019 [00:04<00:02, 1209.91it/s]\u001B[A\n",
" 69%|███████████████████████████████████████▎ | 6214/9019 [00:05<00:02, 1210.27it/s]\u001B[A\n",
" 70%|████████████████████████████████████████ | 6336/9019 [00:05<00:02, 1193.06it/s]\u001B[A\n",
" 72%|████████████████████████████████████████▉ | 6469/9019 [00:05<00:02, 1230.49it/s]\u001B[A\n",
" 73%|█████████████████████████████████████████▋ | 6599/9019 [00:05<00:01, 1248.26it/s]\u001B[A\n",
" 75%|██████████████████████████████████████████▌ | 6728/9019 [00:05<00:01, 1259.77it/s]\u001B[A\n",
" 76%|███████████████████████████████████████████▎ | 6855/9019 [00:05<00:01, 1256.36it/s]\u001B[A\n",
" 77%|████████████████████████████████████████████ | 6981/9019 [00:05<00:01, 1254.71it/s]\u001B[A\n",
" 79%|████████████████████████████████████████████▉ | 7113/9019 [00:05<00:01, 1271.36it/s]\u001B[A\n",
" 80%|█████████████████████████████████████████████▊ | 7246/9019 [00:05<00:01, 1285.23it/s]\u001B[A\n",
" 82%|██████████████████████████████████████████████▌ | 7376/9019 [00:05<00:01, 1286.83it/s]\u001B[A\n",
" 83%|███████████████████████████████████████████████▍ | 7506/9019 [00:06<00:01, 1287.95it/s]\u001B[A\n",
" 85%|████████████████████████████████████████████████▎ | 7635/9019 [00:06<00:01, 1270.68it/s]\u001B[A\n",
" 86%|█████████████████████████████████████████████████ | 7763/9019 [00:06<00:00, 1268.65it/s]\u001B[A\n",
" 87%|█████████████████████████████████████████████████▊ | 7890/9019 [00:06<00:00, 1262.59it/s]\u001B[A\n",
" 89%|██████████████████████████████████████████████████▋ | 8017/9019 [00:06<00:00, 1258.34it/s]\u001B[A\n",
" 90%|███████████████████████████████████████████████████▍ | 8144/9019 [00:06<00:00, 1259.07it/s]\u001B[A\n",
" 92%|████████████████████████████████████████████████████▎ | 8270/9019 [00:06<00:00, 1249.24it/s]\u001B[A\n",
" 93%|█████████████████████████████████████████████████████ | 8395/9019 [00:06<00:00, 1243.10it/s]\u001B[A\n",
" 95%|█████████████████████████████████████████████████████▉ | 8525/9019 [00:06<00:00, 1257.23it/s]\u001B[A\n",
" 96%|██████████████████████████████████████████████████████▋ | 8657/9019 [00:06<00:00, 1273.11it/s]\u001B[A\n",
" 97%|███████████████████████████████████████████████████████▌ | 8785/9019 [00:07<00:00, 1208.04it/s]\u001B[A\n",
"9020it [00:07, 1241.41it/s] \u001B[A"
] ]
}, },
{ {
@ -233,19 +162,12 @@
"text": [ "text": [
" precision recall f1-score support\n", " precision recall f1-score support\n",
"\n", "\n",
" 0 1.00 1.00 1.00 2706\n", " 0 1.00 1.00 1.00 11523\n",
" 1 1.00 1.00 1.00 2255\n", " 1 1.00 1.00 1.00 9603\n",
"\n", "\n",
" accuracy 1.00 4961\n", " accuracy 1.00 21126\n",
" macro avg 1.00 1.00 1.00 4961\n", " macro avg 1.00 1.00 1.00 21126\n",
"weighted avg 1.00 1.00 1.00 4961\n", "weighted avg 1.00 1.00 1.00 21126\n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n" "\n"
] ]
} }

View File

@ -23,7 +23,7 @@ class Config:
blk_model_path = r"./models/rf_4x4_c22_20_sen8_8.model" blk_model_path = r"./models/rf_4x4_c22_20_sen8_8.model"
# rgb模型参数 # rgb模型参数
rgb_tobacco_model_path = r"models/tobacco_dt_2022-07-21_16-30.model" rgb_tobacco_model_path = r"models/tobacco_dt_2022-07-26_15-57.model"
rgb_background_model_path = r"models/beijing_dt_2022-07-21_16-44.model" rgb_background_model_path = r"models/background_dt_2022-07-27_08-11.model"
threshold_low, threshold_high = 5, 255 threshold_low, threshold_high = 5, 255
threshold_s = 175 threshold_s = 175

View File

@ -9,8 +9,7 @@ import cv2
def main(): def main():
spec_detector = SpecDetector(blk_model_path=Config.blk_model_path, spec_detector = SpecDetector(blk_model_path=Config.blk_model_path, pixel_model_path=Config.pixel_model_path)
pixel_model_path=Config.pixel_model_path)
rgb_detector = RgbDetector(tobacco_model_path=Config.rgb_tobacco_model_path, rgb_detector = RgbDetector(tobacco_model_path=Config.rgb_tobacco_model_path,
background_model_path=Config.rgb_background_model_path) background_model_path=Config.rgb_background_model_path)
total_len = Config.nRows * Config.nCols * Config.nBands * 4 # float型变量, 4个字节 total_len = Config.nRows * Config.nCols * Config.nBands * 4 # float型变量, 4个字节
@ -43,9 +42,8 @@ def main():
os.close(fd_rgb) os.close(fd_rgb)
# 识别 # 识别
t1 = time.time() t1 = time.time()
img_data = np.frombuffer(data_total, dtype=np.float32).reshape((Config.nRows, Config.nBands, -1)).transpose(0, img_data = np.frombuffer(data_total, dtype=np.float32).reshape((Config.nRows, Config.nBands, -1)) \
2, .transpose(0, 2, 1)
1)
rgb_data = np.frombuffer(rgb_data_total, dtype=np.uint8).reshape((Config.nRgbRows, Config.nRgbCols, -1)) rgb_data = np.frombuffer(rgb_data_total, dtype=np.uint8).reshape((Config.nRgbRows, Config.nRgbCols, -1))
# 光谱识别 # 光谱识别
mask = spec_detector.predict(img_data) mask = spec_detector.predict(img_data)