From 37c1c446d9e3c25146c8d08db5db64b0b22ff213 Mon Sep 17 00:00:00 2001 From: Tony-HYX <605698554@qq.com> Date: Fri, 3 Mar 2023 14:00:51 +0800 Subject: [PATCH] update package structure --- weights/all_weights_here.txt => abl/__init__.py | 0 abl/abducer/__init__.py | 0 {abducer => abl/abducer}/abducer_base.py | 11 ++++++----- {abducer => abl/abducer}/kb.py | 4 ++-- framework.py => abl/framework.py | 2 +- framework_hed.py => abl/framework_hed.py | 13 ++++++++----- abl/models/__init__.py | 0 {models => abl/models}/basic_model.py | 0 {models => abl/models}/lenet5.py | 0 {models => abl/models}/nn.py | 5 ----- {models => abl/models}/wabl_models.py | 1 - {utils => abl/utils}/plog.py | 0 {utils => abl/utils}/utils.py | 2 +- {datasets => examples/datasets}/data_generator.py | 0 {datasets => examples/datasets}/hed/BK.pl | 0 {datasets => examples/datasets}/hed/README.md | 0 {datasets => examples/datasets}/hed/get_hed.py | 0 {datasets => examples/datasets}/hed/learn_add.pl | 0 {datasets => examples/datasets}/hwf/README.md | 0 {datasets => examples/datasets}/hwf/get_hwf.py | 0 .../datasets}/mnist_add/get_mnist_add.py | 0 .../datasets}/mnist_add/test_data.txt | 0 .../datasets}/mnist_add/train_data.txt | 0 example.py => examples/example.py | 0 nonshare_example.py => examples/nonshare_example.py | 0 share_example.py => examples/share_example.py | 0 examples/weights/all_weights_here.txt | 0 27 files changed, 18 insertions(+), 20 deletions(-) rename weights/all_weights_here.txt => abl/__init__.py (100%) create mode 100644 abl/abducer/__init__.py rename {abducer => abl/abducer}/abducer_base.py (98%) rename {abducer => abl/abducer}/kb.py (99%) rename framework.py => abl/framework.py (98%) rename framework_hed.py => abl/framework_hed.py (97%) create mode 100644 abl/models/__init__.py rename {models => abl/models}/basic_model.py (100%) rename {models => abl/models}/lenet5.py (100%) rename {models => abl/models}/nn.py (97%) rename {models => abl/models}/wabl_models.py (99%) rename {utils => abl/utils}/plog.py (100%) rename {utils => abl/utils}/utils.py (98%) rename {datasets => examples/datasets}/data_generator.py (100%) rename {datasets => examples/datasets}/hed/BK.pl (100%) rename {datasets => examples/datasets}/hed/README.md (100%) rename {datasets => examples/datasets}/hed/get_hed.py (100%) rename {datasets => examples/datasets}/hed/learn_add.pl (100%) rename {datasets => examples/datasets}/hwf/README.md (100%) rename {datasets => examples/datasets}/hwf/get_hwf.py (100%) rename {datasets => examples/datasets}/mnist_add/get_mnist_add.py (100%) rename {datasets => examples/datasets}/mnist_add/test_data.txt (100%) rename {datasets => examples/datasets}/mnist_add/train_data.txt (100%) rename example.py => examples/example.py (100%) rename nonshare_example.py => examples/nonshare_example.py (100%) rename share_example.py => examples/share_example.py (100%) create mode 100644 examples/weights/all_weights_here.txt diff --git a/weights/all_weights_here.txt b/abl/__init__.py similarity index 100% rename from weights/all_weights_here.txt rename to abl/__init__.py diff --git a/abl/abducer/__init__.py b/abl/abducer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/abducer/abducer_base.py b/abl/abducer/abducer_base.py similarity index 98% rename from abducer/abducer_base.py rename to abl/abducer/abducer_base.py index c0fd102..9a483c9 100644 --- a/abducer/abducer_base.py +++ b/abl/abducer/abducer_base.py @@ -10,16 +10,17 @@ # # ================================================================# -import sys +# import sys -sys.path.append(".") -sys.path.append("..") +# sys.path.append(".") +# sys.path.append("..") import abc -from abducer.kb import * +# TODO 尽量别用import * +from .kb import * import numpy as np from zoopt import Dimension, Objective, Parameter, Opt -from utils.utils import confidence_dist, flatten, hamming_dist +from ..utils.utils import confidence_dist, flatten, hamming_dist import math import time diff --git a/abducer/kb.py b/abl/abducer/kb.py similarity index 99% rename from abducer/kb.py rename to abl/abducer/kb.py index bbd6c93..8fb727c 100644 --- a/abducer/kb.py +++ b/abl/abducer/kb.py @@ -21,7 +21,7 @@ sys.path.append("..") from collections import defaultdict from itertools import product, combinations -from utils.utils import flatten, reform_idx, hamming_dist, check_equal +from ..utils.utils import flatten, reform_idx, hamming_dist, check_equal from multiprocessing import Pool @@ -299,7 +299,7 @@ class add_prolog_KB(prolog_KB): class HED_prolog_KB(prolog_KB): def __init__(self, pseudo_label_list=[0, 1, '+', '=']): super().__init__(pseudo_label_list) - self.prolog.consult('./datasets/hed/learn_add.pl') + self.prolog.consult('../examples/datasets/hed/learn_add.pl') # corresponding to `con_sol is not None` in `consistent_score_mapped` within `learn_add.py` def logic_forward(self, exs): diff --git a/framework.py b/abl/framework.py similarity index 98% rename from framework.py rename to abl/framework.py index 2a1fdad..c3a5c6e 100644 --- a/framework.py +++ b/abl/framework.py @@ -14,7 +14,7 @@ import pickle as pk import numpy as np -from utils.plog import INFO, DEBUG, clocker +from .utils.plog import INFO, DEBUG, clocker def block_sample(X, Z, Y, sample_num, epoch_idx): part_num = (len(X) // sample_num) diff --git a/framework_hed.py b/abl/framework_hed.py similarity index 97% rename from framework_hed.py rename to abl/framework_hed.py index b7439c3..d942be6 100644 --- a/framework_hed.py +++ b/abl/framework_hed.py @@ -16,12 +16,15 @@ import torch.nn as nn import numpy as np import os -from utils.plog import INFO, DEBUG, clocker -from utils.utils import flatten, reform_idx, block_sample, gen_mappings, mapping_res, remapping_res +from .utils.plog import INFO, DEBUG, clocker +from .utils.utils import flatten, reform_idx, block_sample, gen_mappings, mapping_res, remapping_res -from models.nn import MLP, SymbolNetAutoencoder -from models.basic_model import BasicModel, BasicDataset -from datasets.hed.get_hed import get_pretrain_data +from .models.nn import MLP, SymbolNetAutoencoder +from .models.basic_model import BasicModel, BasicDataset + +import sys +sys.path.append("..") +from examples.datasets.hed.get_hed import get_pretrain_data def result_statistics(pred_Z, Z, Y, logic_forward, char_acc_flag): result = {} diff --git a/abl/models/__init__.py b/abl/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/models/basic_model.py b/abl/models/basic_model.py similarity index 100% rename from models/basic_model.py rename to abl/models/basic_model.py diff --git a/models/lenet5.py b/abl/models/lenet5.py similarity index 100% rename from models/lenet5.py rename to abl/models/lenet5.py diff --git a/models/nn.py b/abl/models/nn.py similarity index 97% rename from models/nn.py rename to abl/models/nn.py index cecbeea..7a0f560 100644 --- a/models/nn.py +++ b/abl/models/nn.py @@ -10,9 +10,6 @@ # # ================================================================# -import sys - -sys.path.append("..") import torchvision @@ -23,8 +20,6 @@ from torch.autograd import Variable import torchvision.transforms as transforms import numpy as np -from models.basic_model import BasicModel -import utils.plog as plog class LeNet5(nn.Module): diff --git a/models/wabl_models.py b/abl/models/wabl_models.py similarity index 99% rename from models/wabl_models.py rename to abl/models/wabl_models.py index 9c97bbc..3b682ee 100644 --- a/models/wabl_models.py +++ b/abl/models/wabl_models.py @@ -21,7 +21,6 @@ from sklearn.preprocessing import StandardScaler from sklearn.svm import SVC from sklearn.gaussian_process import GaussianProcessClassifier from sklearn.gaussian_process.kernels import RBF -from models.basic_model import BasicModel import pickle as pk import random diff --git a/utils/plog.py b/abl/utils/plog.py similarity index 100% rename from utils/plog.py rename to abl/utils/plog.py diff --git a/utils/utils.py b/abl/utils/utils.py similarity index 98% rename from utils/utils.py rename to abl/utils/utils.py index 1138361..65c85fc 100644 --- a/utils/utils.py +++ b/abl/utils/utils.py @@ -1,5 +1,5 @@ import numpy as np -from utils.plog import INFO +from .plog import INFO from collections import OrderedDict # for multiple predictions, modify from `learn_add.py` diff --git a/datasets/data_generator.py b/examples/datasets/data_generator.py similarity index 100% rename from datasets/data_generator.py rename to examples/datasets/data_generator.py diff --git a/datasets/hed/BK.pl b/examples/datasets/hed/BK.pl similarity index 100% rename from datasets/hed/BK.pl rename to examples/datasets/hed/BK.pl diff --git a/datasets/hed/README.md b/examples/datasets/hed/README.md similarity index 100% rename from datasets/hed/README.md rename to examples/datasets/hed/README.md diff --git a/datasets/hed/get_hed.py b/examples/datasets/hed/get_hed.py similarity index 100% rename from datasets/hed/get_hed.py rename to examples/datasets/hed/get_hed.py diff --git a/datasets/hed/learn_add.pl b/examples/datasets/hed/learn_add.pl similarity index 100% rename from datasets/hed/learn_add.pl rename to examples/datasets/hed/learn_add.pl diff --git a/datasets/hwf/README.md b/examples/datasets/hwf/README.md similarity index 100% rename from datasets/hwf/README.md rename to examples/datasets/hwf/README.md diff --git a/datasets/hwf/get_hwf.py b/examples/datasets/hwf/get_hwf.py similarity index 100% rename from datasets/hwf/get_hwf.py rename to examples/datasets/hwf/get_hwf.py diff --git a/datasets/mnist_add/get_mnist_add.py b/examples/datasets/mnist_add/get_mnist_add.py similarity index 100% rename from datasets/mnist_add/get_mnist_add.py rename to examples/datasets/mnist_add/get_mnist_add.py diff --git a/datasets/mnist_add/test_data.txt b/examples/datasets/mnist_add/test_data.txt similarity index 100% rename from datasets/mnist_add/test_data.txt rename to examples/datasets/mnist_add/test_data.txt diff --git a/datasets/mnist_add/train_data.txt b/examples/datasets/mnist_add/train_data.txt similarity index 100% rename from datasets/mnist_add/train_data.txt rename to examples/datasets/mnist_add/train_data.txt diff --git a/example.py b/examples/example.py similarity index 100% rename from example.py rename to examples/example.py diff --git a/nonshare_example.py b/examples/nonshare_example.py similarity index 100% rename from nonshare_example.py rename to examples/nonshare_example.py diff --git a/share_example.py b/examples/share_example.py similarity index 100% rename from share_example.py rename to examples/share_example.py diff --git a/examples/weights/all_weights_here.txt b/examples/weights/all_weights_here.txt new file mode 100644 index 0000000..e69de29