From f52c8943e13588ea3e99db3a0c5cbcfc58068f6e Mon Sep 17 00:00:00 2001 From: FEIJINTI <83849113+FEIJINTI@users.noreply.github.com> Date: Thu, 21 Jul 2022 17:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=86=A8=E8=83=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02_classification.ipynb | 2 +- 02_classification.py | 2 +- 04_multi_classification.ipynb | 56 +++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/02_classification.ipynb b/02_classification.ipynb index 18552e7..49fb35e 100644 --- a/02_classification.ipynb +++ b/02_classification.ipynb @@ -40,7 +40,7 @@ "color_dict = {(0, 0, 255): \"yangeng\", (255, 0, 0): 'beijing',(0, 255, 0): \"zibian\"} # 颜色对应的类别\n", "# color_dict = {(0, 0, 255): \"yangeng\"}\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", "show_samples = False # 是否展示样本\n", "\n", diff --git a/02_classification.py b/02_classification.py index ef3ad4a..a372828 100644 --- a/02_classification.py +++ b/02_classification.py @@ -14,7 +14,7 @@ color_dict = {(0, 0, 255): "yangeng", (255, 0, 0): 'beijing', (0, 255, 0): "zibi # color_dict = {(255, 0, 0): 'beijing'} # color_dict = {(0, 255, 0): "zibian"} label_index = {"yangeng": 1, "beijing": 0, "zibian": 2} # 类别对应的序号 -show_samples = False # 是否展示样本 +show_samples = True # 是否展示样本 # 定义一些训练量 threshold = 5 # 正样本周围多大范围内的还算是正样本 diff --git a/04_multi_classification.ipynb b/04_multi_classification.ipynb index 9e85ffb..3f30c7d 100644 --- a/04_multi_classification.ipynb +++ b/04_multi_classification.ipynb @@ -14,7 +14,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 17, "outputs": [], "source": [ "import datetime\n", @@ -25,7 +25,7 @@ "import numpy as np\n", "import pickle\n", "from sklearn.tree import DecisionTreeClassifier\n", - "%matplotlib notebook\n", + "# %matplotlib notebook\n", "from main_test import virtual_main\n", "from models import AnonymousColorDetector\n", "from utils import lab_scatter" @@ -39,11 +39,11 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 18, "outputs": [], "source": [ "img_path = r\"C:\\Users\\FEIJINTI\\Desktop\\721\\zazhi\\Image_2022_0721_1351_38_946-002034.bmp\"\n", - "model_path = [\"models/beijing_dt_2022-07-21_16-44.model\", \"models/tobacco_dt_2022-07-21_16-30.model\",\"models/zibian_dt_2022-07-21_16-45.model\"]" + "model_path = [\"models/beijing_dt_2022-07-21_16-44.model\", \"models/tobacco_dt_2022-07-21_16-30.model\",\"models/zibian_dt_2022-07-21_16-45.model\",\"dt_2022-07-21_17-19.model\"]" ], "metadata": { "collapsed": false, @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 19, "outputs": [], "source": [ "img = cv2.imread(img_path)[:, :, ::-1]\n", @@ -71,11 +71,12 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 20, "outputs": [], "source": [ "t_detector = AnonymousColorDetector(file_path=model_path[1])\n", - "t_result = t_detector.predict(img).astype(np.uint8)" + "t_result = t_detector.predict(img).astype(np.uint8)\n", + "t_result = cv2.dilate(t_result, kernel = np.ones((3, 3), np.uint8))" ], "metadata": { "collapsed": false, @@ -86,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 21, "outputs": [], "source": [ "z_detector = AnonymousColorDetector(file_path=model_path[2])\n", @@ -101,10 +102,11 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 22, "outputs": [], "source": [ - "result = 1 - (b_result | t_result | z_result)" + "s_detector = AnonymousColorDetector(file_path=model_path[3])\n", + "s_result = s_detector.predict(img).astype(np.uint8)" ], "metadata": { "collapsed": false, @@ -115,7 +117,21 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 25, + "outputs": [], + "source": [ + "result = 1 - (b_result | t_result)" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 26, "outputs": [ { "data": { @@ -128,26 +144,20 @@ { "data": { "text/plain": "", - "text/html": "
" + "text/html": "
" }, "metadata": {}, "output_type": "display_data" - }, - { - "data": { - "text/plain": "" - }, - "execution_count": 50, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ - "fig,axs = plt.subplots(4,1)\n", + "fig,axs = plt.subplots(5,1)\n", "axs[0].imshow(b_result)\n", "axs[1].imshow(t_result)\n", "axs[2].imshow(z_result)\n", - "axs[3].imshow(result)" + "axs[3].imshow(result)\n", + "axs[4].imshow(1-s_result)\n", + "plt.savefig(\"1.png\",dpi=900)" ], "metadata": { "collapsed": false, @@ -158,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 24, "outputs": [], "source": [], "metadata": {