From 5b9a028e60c7f029f9e12df65e602c50cdddc0a5 Mon Sep 17 00:00:00 2001
From: D-X-Y <280835372@qq.com>
Date: Wed, 19 May 2021 07:19:20 +0000
Subject: [PATCH] Refine lib -> xautodl
---
docs/NeurIPS-2019-TAS.md | 6 +++---
exps/LFNA/lfna.py | 4 ++--
exps/LFNA/lfna_utils.py | 4 ++--
exps/NATS-Bench/main-tss.py | 4 ++--
exps/{ => TAS}/prepare.py | 11 ++++++-----
scripts/TAS/prepare.sh | 13 +++++++++++++
scripts/prepare.sh | 13 -------------
xautodl/models/cell_infers/cells.py | 2 +-
xautodl/models/cell_infers/nasnet_cifar.py | 1 +
xautodl/models/xcore.py | 10 +++++-----
xautodl/procedures/advanced_main.py | 3 +--
xautodl/procedures/basic_main.py | 3 +--
xautodl/procedures/eval_funcs.py | 2 +-
xautodl/procedures/funcs_nasbench.py | 2 +-
xautodl/procedures/q_exps.py | 1 -
xautodl/procedures/search_main.py | 5 +++--
xautodl/procedures/search_main_v2.py | 4 ++--
xautodl/procedures/simple_KD_main.py | 2 +-
xautodl/procedures/starts.py | 2 +-
19 files changed, 46 insertions(+), 46 deletions(-)
rename exps/{ => TAS}/prepare.py (89%)
create mode 100644 scripts/TAS/prepare.sh
delete mode 100644 scripts/prepare.sh
diff --git a/docs/NeurIPS-2019-TAS.md b/docs/NeurIPS-2019-TAS.md
index 12c6bf4..fb87976 100644
--- a/docs/NeurIPS-2019-TAS.md
+++ b/docs/NeurIPS-2019-TAS.md
@@ -7,8 +7,8 @@ In this paper, we proposed a differentiable searching strategy for transformable
You could see the highlight of our Transformable Architecture Search (TAS) at our [project page](https://xuanyidong.com/assets/projects/NeurIPS-2019-TAS.html).
-
-
+
+
@@ -24,7 +24,7 @@ We provide some logs at [Google Drive](https://drive.google.com/open?id=1_qUY4DT
## Usage
-Use `bash ./scripts/prepare.sh` to prepare data splits for `CIFAR-10`, `CIFARR-100`, and `ILSVRC2012`.
+Use `bash ./scripts/TAS/prepare.sh` to prepare data splits for `CIFAR-10`, `CIFARR-100`, and `ILSVRC2012`.
If you do not have `ILSVRC2012` data, please comment L12 in `./scripts/prepare.sh`.
args: `cifar10` indicates the dataset name, `ResNet56` indicates the basemodel name, `CIFARX` indicates the searching hyper-parameters, `0.47/0.57` indicates the expected FLOP ratio, `-1` indicates the random seed.
diff --git a/exps/LFNA/lfna.py b/exps/LFNA/lfna.py
index 189044e..593d133 100644
--- a/exps/LFNA/lfna.py
+++ b/exps/LFNA/lfna.py
@@ -27,8 +27,8 @@ from xautodl.datasets.synthetic_core import get_synthetic_env, EnvSampler
from xautodl.models.xcore import get_model
from xautodl.xlayers import super_core, trunc_normal_
-from xautodl.lfna_utils import lfna_setup, train_model, TimeData
-from xautodl.lfna_meta_model import LFNA_Meta
+from lfna_utils import lfna_setup, train_model, TimeData
+from lfna_meta_model import LFNA_Meta
def epoch_train(loader, meta_model, base_model, optimizer, criterion, device, logger):
diff --git a/exps/LFNA/lfna_utils.py b/exps/LFNA/lfna_utils.py
index f78727e..44489e1 100644
--- a/exps/LFNA/lfna_utils.py
+++ b/exps/LFNA/lfna_utils.py
@@ -4,8 +4,8 @@
import copy
import torch
from tqdm import tqdm
-from procedures import prepare_seed, prepare_logger
-from datasets.synthetic_core import get_synthetic_env
+from xautodl.procedures import prepare_seed, prepare_logger
+from xautodl.datasets.synthetic_core import get_synthetic_env
def lfna_setup(args):
diff --git a/exps/NATS-Bench/main-tss.py b/exps/NATS-Bench/main-tss.py
index e3e1016..dd5ec15 100644
--- a/exps/NATS-Bench/main-tss.py
+++ b/exps/NATS-Bench/main-tss.py
@@ -665,7 +665,7 @@ if __name__ == "__main__":
len(args.datasets), len(args.xpaths), len(args.splits)
)
)
- if args.workers <= 0:
+ if args.workers < 0:
raise ValueError("invalid number of workers : {:}".format(args.workers))
target_indexes = filter_indexes(
@@ -675,7 +675,7 @@ if __name__ == "__main__":
assert torch.cuda.is_available(), "CUDA is not available."
torch.backends.cudnn.enabled = True
torch.backends.cudnn.deterministic = True
- torch.set_num_threads(args.workers)
+ torch.set_num_threads(args.workers if args.workers > 0 else 1)
main(
save_dir,
diff --git a/exps/prepare.py b/exps/TAS/prepare.py
similarity index 89%
rename from exps/prepare.py
rename to exps/TAS/prepare.py
index 6ac50a4..94ff723 100644
--- a/exps/prepare.py
+++ b/exps/TAS/prepare.py
@@ -1,6 +1,10 @@
+#####################################################
+# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2021.01 #
+#####################################################
# python exps/prepare.py --name cifar10 --root $TORCH_HOME/cifar.python --save ./data/cifar10.split.pth
# python exps/prepare.py --name cifar100 --root $TORCH_HOME/cifar.python --save ./data/cifar100.split.pth
# python exps/prepare.py --name imagenet-1k --root $TORCH_HOME/ILSVRC2012 --save ./data/imagenet-1k.split.pth
+#####################################################
import sys, time, torch, random, argparse
from collections import defaultdict
import os.path as osp
@@ -12,9 +16,6 @@ from pathlib import Path
import torchvision
import torchvision.datasets as dset
-lib_dir = (Path(__file__).parent / ".." / "lib").resolve()
-if str(lib_dir) not in sys.path:
- sys.path.insert(0, str(lib_dir))
parser = argparse.ArgumentParser(
description="Prepare splits for searching",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
@@ -35,9 +36,9 @@ def main():
print("torchvision version : {:}".format(torchvision.__version__))
if name == "cifar10":
- dataset = dset.CIFAR10(args.root, train=True)
+ dataset = dset.CIFAR10(args.root, train=True, download=True)
elif name == "cifar100":
- dataset = dset.CIFAR100(args.root, train=True)
+ dataset = dset.CIFAR100(args.root, train=True, download=True)
elif name == "imagenet-1k":
dataset = dset.ImageFolder(osp.join(args.root, "train"))
else:
diff --git a/scripts/TAS/prepare.sh b/scripts/TAS/prepare.sh
new file mode 100644
index 0000000..005d552
--- /dev/null
+++ b/scripts/TAS/prepare.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+# bash ./scripts/TAS/prepare.sh
+#datasets='cifar10 cifar100 imagenet-1k'
+#ratios='0.5 0.8 0.9'
+ratios='0.5'
+save_dir=./.latent-data/splits
+
+for ratio in ${ratios}
+do
+ python ./exps/TAS/prepare.py --name cifar10 --root $TORCH_HOME/cifar.python --save ${save_dir}/cifar10-${ratio}.pth --ratio ${ratio}
+ python ./exps/TAS/prepare.py --name cifar100 --root $TORCH_HOME/cifar.python --save ${save_dir}/cifar100-${ratio}.pth --ratio ${ratio}
+ python ./exps/TAS/prepare.py --name imagenet-1k --root $TORCH_HOME/ILSVRC2012 --save ${save_dir}/imagenet-1k-${ratio}.pth --ratio ${ratio}
+done
diff --git a/scripts/prepare.sh b/scripts/prepare.sh
deleted file mode 100644
index 3bf7150..0000000
--- a/scripts/prepare.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-# bash ./scripts/prepare.sh
-#datasets='cifar10 cifar100 imagenet-1k'
-#ratios='0.5 0.8 0.9'
-ratios='0.5'
-save_dir=./.latent-data/splits
-
-for ratio in ${ratios}
-do
- python ./exps/prepare.py --name cifar10 --root $TORCH_HOME/cifar.python --save ${save_dir}/cifar10-${ratio}.pth --ratio ${ratio}
- python ./exps/prepare.py --name cifar100 --root $TORCH_HOME/cifar.python --save ${save_dir}/cifar100-${ratio}.pth --ratio ${ratio}
- python ./exps/prepare.py --name imagenet-1k --root $TORCH_HOME/ILSVRC2012 --save ${save_dir}/imagenet-1k-${ratio}.pth --ratio ${ratio}
-done
diff --git a/xautodl/models/cell_infers/cells.py b/xautodl/models/cell_infers/cells.py
index 40df57b..1fa2e98 100644
--- a/xautodl/models/cell_infers/cells.py
+++ b/xautodl/models/cell_infers/cells.py
@@ -6,7 +6,7 @@ import torch
import torch.nn as nn
from copy import deepcopy
-from models.cell_operations import OPS
+from xautodl.models.cell_operations import OPS
# Cell for NAS-Bench-201
diff --git a/xautodl/models/cell_infers/nasnet_cifar.py b/xautodl/models/cell_infers/nasnet_cifar.py
index bdef399..2109477 100644
--- a/xautodl/models/cell_infers/nasnet_cifar.py
+++ b/xautodl/models/cell_infers/nasnet_cifar.py
@@ -4,6 +4,7 @@
import torch
import torch.nn as nn
from copy import deepcopy
+
from .cells import NASNetInferCell as InferCell, AuxiliaryHeadCIFAR
diff --git a/xautodl/models/xcore.py b/xautodl/models/xcore.py
index 819f272..e7e6b5b 100644
--- a/xautodl/models/xcore.py
+++ b/xautodl/models/xcore.py
@@ -9,11 +9,11 @@ import torch
__all__ = ["get_model"]
-from xlayers.super_core import SuperSequential
-from xlayers.super_core import SuperLinear
-from xlayers.super_core import SuperDropout
-from xlayers.super_core import super_name2norm
-from xlayers.super_core import super_name2activation
+from xautodl.xlayers.super_core import SuperSequential
+from xautodl.xlayers.super_core import SuperLinear
+from xautodl.xlayers.super_core import SuperDropout
+from xautodl.xlayers.super_core import super_name2norm
+from xautodl.xlayers.super_core import super_name2activation
def get_model(config: Dict[Text, Any], **kwargs):
diff --git a/xautodl/procedures/advanced_main.py b/xautodl/procedures/advanced_main.py
index dfb32f9..854fe63 100644
--- a/xautodl/procedures/advanced_main.py
+++ b/xautodl/procedures/advanced_main.py
@@ -7,8 +7,7 @@ import os, sys, time, torch
from typing import Optional, Text, Callable
# modules in AutoDL
-from log_utils import AverageMeter
-from log_utils import time_string
+from xautodl.log_utils import AverageMeter, time_string
from .eval_funcs import obtain_accuracy
diff --git a/xautodl/procedures/basic_main.py b/xautodl/procedures/basic_main.py
index 94ca90f..1d74978 100644
--- a/xautodl/procedures/basic_main.py
+++ b/xautodl/procedures/basic_main.py
@@ -4,8 +4,7 @@
import os, sys, time, torch
# modules in AutoDL
-from log_utils import AverageMeter
-from log_utils import time_string
+from xautodl.log_utils import AverageMeter, time_string
from .eval_funcs import obtain_accuracy
diff --git a/xautodl/procedures/eval_funcs.py b/xautodl/procedures/eval_funcs.py
index 99b569b..006ba35 100644
--- a/xautodl/procedures/eval_funcs.py
+++ b/xautodl/procedures/eval_funcs.py
@@ -15,6 +15,6 @@ def obtain_accuracy(output, target, topk=(1,)):
res = []
for k in topk:
- correct_k = correct[:k].view(-1).float().sum(0, keepdim=True)
+ correct_k = correct[:k].contiguous().view(-1).float().sum(0, keepdim=True)
res.append(correct_k.mul_(100.0 / batch_size))
return res
diff --git a/xautodl/procedures/funcs_nasbench.py b/xautodl/procedures/funcs_nasbench.py
index bd0682a..00566a9 100644
--- a/xautodl/procedures/funcs_nasbench.py
+++ b/xautodl/procedures/funcs_nasbench.py
@@ -4,7 +4,7 @@
import os, time, copy, torch, pathlib
# modules in AutoDL
-import xautodl.datasets
+from xautodl import datasets
from xautodl.config_utils import load_config
from xautodl.procedures import prepare_seed, get_optim_scheduler
from xautodl.log_utils import AverageMeter, time_string, convert_secs2time
diff --git a/xautodl/procedures/q_exps.py b/xautodl/procedures/q_exps.py
index 48a6b7e..22bf248 100644
--- a/xautodl/procedures/q_exps.py
+++ b/xautodl/procedures/q_exps.py
@@ -8,7 +8,6 @@ import pprint
import logging
from copy import deepcopy
-from log_utils import pickle_load
import qlib
from qlib.utils import init_instance_by_config
from qlib.workflow import R
diff --git a/xautodl/procedures/search_main.py b/xautodl/procedures/search_main.py
index 8d2b209..920ddbd 100644
--- a/xautodl/procedures/search_main.py
+++ b/xautodl/procedures/search_main.py
@@ -2,8 +2,9 @@
# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2019 #
##################################################
import os, sys, time, torch
-from log_utils import AverageMeter, time_string
-from models import change_key
+
+from xautodl.log_utils import AverageMeter, time_string
+from xautodl.models import change_key
from .eval_funcs import obtain_accuracy
diff --git a/xautodl/procedures/search_main_v2.py b/xautodl/procedures/search_main_v2.py
index 03139c4..14ab16c 100644
--- a/xautodl/procedures/search_main_v2.py
+++ b/xautodl/procedures/search_main_v2.py
@@ -4,8 +4,8 @@
import os, sys, time, torch
# modules in AutoDL
-from log_utils import AverageMeter, time_string
-from models import change_key
+from xautodl.log_utils import AverageMeter, time_string
+from xautodl.models import change_key
from .eval_funcs import obtain_accuracy
diff --git a/xautodl/procedures/simple_KD_main.py b/xautodl/procedures/simple_KD_main.py
index 211dce8..0d31431 100644
--- a/xautodl/procedures/simple_KD_main.py
+++ b/xautodl/procedures/simple_KD_main.py
@@ -5,7 +5,7 @@ import os, sys, time, torch
import torch.nn.functional as F
# modules in AutoDL
-from log_utils import AverageMeter, time_string
+from xautodl.log_utils import AverageMeter, time_string
from .eval_funcs import obtain_accuracy
diff --git a/xautodl/procedures/starts.py b/xautodl/procedures/starts.py
index 1ae19c5..b315521 100644
--- a/xautodl/procedures/starts.py
+++ b/xautodl/procedures/starts.py
@@ -16,7 +16,7 @@ def prepare_seed(rand_seed):
def prepare_logger(xargs):
args = copy.deepcopy(xargs)
- from log_utils import Logger
+ from xautodl.log_utils import Logger
logger = Logger(args.save_dir, args.rand_seed)
logger.log("Main Function with logger : {:}".format(logger))