コード例 #1
0
    def get_bm_rec_info(self):
        """
        get_info:放 ..._names
                      ├ ..._read_paths
                      └ ..._write_paths
                     file_amount
        """
        self.bm_names = get_dir_certain_file_names(self.bm_visual_read_dir,
                                                   certain_word="bm_epoch",
                                                   certain_ext=".jpg")
        self.bm_read_paths = [
            self.bm_visual_read_dir + "/" + name for name in self.bm_names
        ]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!

        self.rec_names = get_dir_certain_file_names(self.rec_visual_read_dir,
                                                    certain_word="rec_epoch",
                                                    certain_ext=".jpg")
        self.rec_read_paths = [
            self.rec_visual_read_dir + "/" + name for name in self.rec_names
        ]  ### 沒有 write_path, 因為 bm_rec 只需要指定 write_dir 即可寫入資料夾

        self.rec_gt_path = self.get_path_savely(
            self.rec_visual_read_dir, certain_word="gt", certain_ext=".jpg"
        )  ### 沒有 write_path, 因為 bm_rec 只需要指定 write_dir 即可寫入資料夾
        # self.rec_gt_name = get_dir_certain_file_names(self.rec_visual_read_dir, certain_word="gt", certain_ext=".jpg")
        # self.rec_gt_path = self.rec_visual_read_dir + "/" + self.rec_gt_name[0]

        self.see_rec_amount = len(self.rec_read_paths)
        self.trained_epoch = self.see_rec_amount - 1  ### 去掉epoch0
コード例 #2
0
    def get_npz_info(self):
        """
        get_info:放 ..._names
                      ├ ..._read_paths
                      └ ..._write_paths
                     file_amount
        """
        self.flow_gt_npz_path = self.get_path_savely(self.npz_read_dir,
                                                     certain_word="gt_flow",
                                                     certain_ext=".npz")
        if (self.flow_gt_npz_path is None):
            self.flow_gt_npz_path = self.get_path_savely(self.npz_read_dir,
                                                         certain_word="Fgt",
                                                         certain_ext=".npz")
        # self.flow_gt_npz_names    = get_dir_certain_file_names(self.npz_read_dir, certain_word="gt_flow", certain_ext=".npz")
        # if(len(self.flow_gt_npz_names) > 0): self.flow_gt_npz_path = f"{self.npz_read_dir}/{self.flow_gt_npz_names[0]}"
        # else: print(f"{self.npz_read_dir} 找不到 gt_flow.npz")

        ### 不包含 gt_flow 的 list喔!
        self.npz_epoch_mask_names = get_dir_certain_file_names(
            self.npz_read_dir,
            certain_word="epoch",
            certain_word2="mask",
            certain_ext=".npz")
        self.npz_epoch_flow_names = get_dir_certain_file_names(
            self.npz_read_dir,
            certain_word="epoch",
            certain_word2="flow",
            certain_ext=".npz")
        if (len(self.npz_epoch_flow_names) == 0):
            self.npz_epoch_flow_names = get_dir_certain_file_names(
                self.npz_read_dir,
                certain_word="epoch",
                certain_word2="F.npz",
                certain_ext=".npz")
        if (len(self.npz_epoch_flow_names) == 0):
            self.npz_epoch_flow_names = get_dir_certain_file_names(
                self.npz_read_dir,
                certain_word="epoch",
                certain_word2="F_w_Mgt.npz",
                certain_ext=".npz")

        self.npz_epoch_mask_read_paths = [
            self.npz_read_dir + "/" + npz_epoch_mask_name
            for npz_epoch_mask_name in self.npz_epoch_mask_names
        ]  ### 沒有 write_paths,同上 ,既然已經沒有 self.see_npz_write_paths, 當然更不會有 self.see_npz_epoch_write_paths 拉!
        self.npz_epoch_flow_read_paths = [
            self.npz_read_dir + "/" + npz_epoch_flow_name
            for npz_epoch_flow_name in self.npz_epoch_flow_names
        ]  ### 沒有 write_paths,同上 ,既然已經沒有 self.see_npz_write_paths, 當然更不會有 self.see_npz_epoch_write_paths 拉!

        self.npz_epoch_amount = len(self.npz_epoch_flow_read_paths)
コード例 #3
0
    def step0_save_code(self):
        '''
        把 step.py 和 kong_util資料夾 存一份進result
        '''
        import shutil
        from build_dataset_combine import Check_dir_exist_and_build
        code_save_path = self.result_obj.train_code_write_dir                 ### 定位出 result存code的目的地
        print("code_save_path:", code_save_path)
        Check_dir_exist_and_build(code_save_path)                             ### 建立目的地資料夾

        py_file_names = get_dir_certain_file_names(kong_model2_dir, certain_word="step")  ### 抓取目前目錄所有 有含 "step" 的檔名
        for py_file_name in py_file_names:
            ### 這兩行可以 抓 step"幾" 然後只存 step"幾".py 喔,但還沒整理以前的code,保險起見還是全存好了,有空再細細處理~~
            # py_file_name_step = int(py_file_name.split("_")[0][4:])          ### 抓出 step "幾"
            # if(py_file_name_step >= 6 or py_file_name_step == 0):            ### step06 以上
            shutil.copy(f"{kong_model2_dir}/{py_file_name}", f"{code_save_path}/{py_file_name}")     ### 存起來

        ### 因為我現在有加 timestamp, 所以 不會有上一版 kong_util的問題, 所以可以註解掉囉~
        # if(os.path.isdir(code_save_path + "/" + "kong_util")):  ### 在train_reload時 如果有舊的kong_util,把舊的刪掉換新的
        #     shutil.rmtree(code_save_path + "/" + "kong_util")
        # print("self.exp_dir:", self.exp_dir )
        shutil.copytree(f"{kong_model2_dir}/kong_util", code_save_path + "/" + "kong_util")
        shutil.copytree(f"{kong_model2_dir}/kong_Blender", code_save_path + "/" + "kong_Blender")
        shutil.copytree(f"{kong_model2_dir}/SIFT_dev", code_save_path + "/" + "SIFT_dev")

        code_exe_copy_src = "/".join(self.code_exe_path.split("\\")[:-1])
        code_exe_copy_dst = code_save_path + "/" + "/".join(self.code_exe_path.split("\\")[-3:-1])
        # print("self.code_exe_path:", self.code_exe_path)  ### 舉例: c:\Users\CVML\Desktop\kong_model2\step10_6_mask\mask_5_8b_ch032_tv_s100_bce_s001_100_sobel_k5_s001_100\step10_a.py
        # print("code_exe_copy_src:", code_exe_copy_src)    ### 舉例: c:/Users/CVML/Desktop/kong_model2/step10_6_mask/mask_5_8b_ch032_tv_s100_bce_s001_100_sobel_k5_s001_100
        # print("code_exe_copy_dst:", code_exe_copy_dst)    ### 舉例: data_dir/result/6_mask_unet/5_8b_ch032_tv_s100_bce_s001_100_sobel_k5_s001_100/type8_blender_os_book-8b_6_6-flow_unet-mask_h_bg_ch032_sig_tv_s100_bce_s100_sobel_k5_s100_6l_ep060-20211116_125312/train_code_20211116_125312/step10_6_mask/mask_5_8b_ch032_tv_s100_bce_s001_100_sobel_k5_s001_100
        shutil.copytree(code_exe_copy_src, code_exe_copy_dst)
コード例 #4
0
    def get_path_savely(self,
                        search_dir_1,
                        search_dir_2=".",
                        certain_word=".",
                        certain_ext="."):
        names = get_dir_certain_file_names(search_dir_1,
                                           certain_word=certain_word,
                                           certain_ext=certain_ext)
        if (len(names) > 0): return f"{search_dir_1}/{names[-1]}"

        ### 如果 search_dir_1 找不到就去 search_dir_2 找
        names = get_dir_certain_file_names(search_dir_2,
                                           certain_word=certain_word,
                                           certain_ext=certain_ext)
        if (len(names) > 0): return f"{search_dir_2}/{names[-1]}"

        ### 如果 search_dir_1, 2 就代表真的找不到了
        print(f"{search_dir_1} 找不到 {certain_word}{certain_ext} 字眼的檔案")
        print(f"{search_dir_2} 找不到 {certain_word}{certain_ext} 字眼的檔案")
        return None
コード例 #5
0
    def get_mask_info(self):
        """
        get_info:放 ..._names
                      ├ ..._read_paths
                      └ ..._write_paths
                     file_amount
        """
        self.mask_names = get_dir_certain_file_names(self.mask_read_dir,
                                                     certain_word="epoch",
                                                     certain_ext=".bmp")
        self.mask_read_paths = [
            self.mask_read_dir + "/" + name for name in self.mask_names
        ]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!

        self.mask_amount = len(self.mask_read_paths)
        self.trained_epoch = self.mask_amount - 1  ### 去掉epoch0
コード例 #6
0
    def get_metric_info(self):
        """
        get_info:放 ..._names
                      ├ ..._read_paths
                      └ ..._write_paths
                     file_amount
        """
        # self.metric_names  = get_dir_certain_file_names(self.metrec_read_dir , certain_word="metric_epoch", certain_ext=".jpg")
        # self.metric_read_paths  = [self.matplot_metric_visual_read_dir + "/" + name for name in self.metric_names]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!

        self.ld_color_visual_names = get_dir_certain_file_names(
            self.metric_ld_color_read_dir,
            certain_word="ld_epoch",
            certain_ext=".jpg")
        self.ld_color_visual_read_path = [
            self.metric_ld_color_read_dir + "/" + name
            for name in self.ld_color_visual_names
        ]  ### 沒有 write_path, 因為 ld_visual 只需要指定 write_dir 即可寫入資料夾
コード例 #7
0
    def get_npy_info(self):
        """
        get_info:放 ..._names
                      ├ ..._read_paths
                      └ ..._write_paths
                     file_amount
        """
        self.flow_gt_npy_path = self.get_path_savely(self.npy_read_dir,
                                                     certain_word="gt_flow",
                                                     certain_ext=".npy")
        # self.gt_flow_names = get_dir_certain_file_names(self.npy_read_dir, certain_word="gt_flow", certain_ext=".npy")
        # if(len(self.gt_flow_name) > 0): self.flow_gt_npy_path = self.npy_read_dir + "/" + self.gt_flow_names[0]
        # else: print(f"{self.npy_read_dir} 找不到 gt_flow.npy")

        self.npy_names = get_dir_certain_file_names(self.npy_read_dir,
                                                    certain_word=".npy")
        self.npy_read_paths = [
            self.npy_read_dir + "/" + npy_name for npy_name in self.npy_names
        ]  ### 沒有 write_paths,因為式 npy轉npz, 不會有寫npy的動作, 雖然下面的 compare 會寫一點npy, 但也因為 有用 .replace() 所以用 see_npy_name.replace() 較保險這樣子!
        self.npy_amount = len(self.npy_read_paths)
コード例 #8
0
    def get_flow_info(self):
        self.gt_flow_jpg_path = self.get_path_savely(self.see_read_dir,
                                                     certain_word="gt_flow",
                                                     certain_ext=".jpg")
        if (self.gt_flow_jpg_path is None):
            self.gt_flow_jpg_path = self.get_path_savely(self.see_read_dir,
                                                         certain_word="Fgt",
                                                         certain_ext=".jpg")
        self.rec_hope_path = self.get_path_savely(
            self.flow_v_read_dir, certain_word="rec_hope", certain_ext=".jpg"
        )  ### search_dir_1 設 self.flow_v_write_dir 是因為 有可能 npy_to_npz 完 馬上就接著做
        # self.rec_hope_path    = self.get_path_savely(self.flow_v_write_dir, search_dir_2=self.flow_v_read_dir, certain_word="rec_hope", certain_ext=".jpg")  ### search_dir_1 設 self.flow_v_write_dir 是因為 有可能 npy_to_npz 完 馬上就接著做, 不過我有寫同步 應該可以試試看 直接 只看 read_dir囉~

        self.flow_ep_jpg_names = get_dir_certain_file_names(
            self.see_read_dir,
            certain_word="epoch",
            certain_word2="flow",
            certain_ext=".jpg")
        if (len(self.flow_ep_jpg_names) == 0):
            self.flow_ep_jpg_names = get_dir_certain_file_names(
                self.see_read_dir,
                certain_word="epoch",
                certain_word2="F.jpg",
                certain_ext=".jpg")
        if (len(self.flow_ep_jpg_names) == 0):
            self.flow_ep_jpg_names = get_dir_certain_file_names(
                self.see_read_dir,
                certain_word="epoch",
                certain_word2="F_w_Mgt.jpg",
                certain_ext=".jpg")
        self.flow_ep_jpg_read_paths = [
            self.see_read_dir + "/" + epoch_name
            for epoch_name in self.flow_ep_jpg_names
        ]  ### 沒有 write_paths, 同上
        self.flow_ep_jpg_amount = len(self.flow_ep_jpg_names)

        self.Cx_names = get_dir_certain_file_names(self.Cx_read_dir,
                                                   certain_word="epoch",
                                                   certain_word2="Cx.jpg",
                                                   certain_ext=".jpg")
        if (len(self.Cx_names) == 0):
            self.Cx_names = get_dir_certain_file_names(
                self.Cx_read_dir,
                certain_word="epoch",
                certain_word2="Cx_visual.jpg",
                certain_ext=".jpg")
        if (len(self.Cx_names) == 0):
            self.Cx_names = get_dir_certain_file_names(
                self.Cx_read_dir,
                certain_word="epoch",
                certain_word2="Cx_w_Mgt.jpg",
                certain_ext=".jpg")
        self.Cy_names = get_dir_certain_file_names(self.Cy_read_dir,
                                                   certain_word="epoch",
                                                   certain_word2="Cy.jpg",
                                                   certain_ext=".jpg")
        if (len(self.Cy_names) == 0):
            self.Cy_names = get_dir_certain_file_names(
                self.Cy_read_dir,
                certain_word="epoch",
                certain_word2="Cy_visual.jpg",
                certain_ext=".jpg")
        if (len(self.Cy_names) == 0):
            self.Cy_names = get_dir_certain_file_names(
                self.Cy_read_dir,
                certain_word="epoch",
                certain_word2="Cy_w_Mgt.jpg",
                certain_ext=".jpg")
        self.Cx_read_paths = [
            self.Cx_read_dir + "/" + name for name in self.Cx_names
        ]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!
        self.Cy_read_paths = [
            self.Cy_read_dir + "/" + name for name in self.Cy_names
        ]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!

        self.trained_epoch = self.flow_ep_jpg_amount - 1  ### 去掉epoch0
コード例 #9
0
    def get_wc_info(self):
        """
        get_info:放 ..._names
                      ├ ..._read_paths
                      └ ..._write_paths
                     file_amount
        """
        self.wc_names = get_dir_certain_file_names(self.wc_read_dir,
                                                   certain_word="epoch",
                                                   certain_word2="wc",
                                                   certain_ext=".jpg")
        if (len(self.wc_names) == 0):
            self.wc_names = get_dir_certain_file_names(
                self.wc_read_dir,
                certain_word="epoch",
                certain_word2="W_visual",
                certain_ext=".jpg")

        self.wx_names = get_dir_certain_file_names(self.wx_read_dir,
                                                   certain_word="epoch",
                                                   certain_word2="wx",
                                                   certain_ext=".jpg")
        if (len(self.wx_names) == 0):
            self.wx_names = get_dir_certain_file_names(
                self.wx_read_dir,
                certain_word="epoch",
                certain_word2="Wx_visual",
                certain_ext=".jpg")
        self.wy_names = get_dir_certain_file_names(self.wy_read_dir,
                                                   certain_word="epoch",
                                                   certain_word2="wy",
                                                   certain_ext=".jpg")
        if (len(self.wy_names) == 0):
            self.wy_names = get_dir_certain_file_names(
                self.wy_read_dir,
                certain_word="epoch",
                certain_word2="Wy_visual",
                certain_ext=".jpg")
        self.wz_names = get_dir_certain_file_names(self.wz_read_dir,
                                                   certain_word="epoch",
                                                   certain_word2="wz",
                                                   certain_ext=".jpg")
        if (len(self.wz_names) == 0):
            self.wz_names = get_dir_certain_file_names(
                self.wz_read_dir,
                certain_word="epoch",
                certain_word2="Wz_visual",
                certain_ext=".jpg")

        self.wc_read_paths = [
            self.wc_read_dir + "/" + name for name in self.wc_names
        ]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!
        self.wx_read_paths = [
            self.wx_read_dir + "/" + name for name in self.wx_names
        ]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!
        self.wy_read_paths = [
            self.wy_read_dir + "/" + name for name in self.wy_names
        ]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!
        self.wz_read_paths = [
            self.wz_read_dir + "/" + name for name in self.wz_names
        ]  ### 目前還沒用到~ 所以也沒有寫 write_path 囉!

        self.wc_amount = len(self.wc_read_paths)
        self.trained_epoch = self.wc_amount - 1  ### 去掉epoch0