Closed liuwei3612 closed 3 years ago
明明安装好了torch,怎么还报这个错误
import torch in your exp file: "exps/yolox_tiny/yolox_tiny.py"
import torch in your exp file: "exps/yolox_tiny/yolox_tiny.py"
import os
from yolox.exp import Exp as MyExp from yolox.data import get_yolox_datadir
class Exp(MyExp): def init(self): super(Exp, self).init() self.depth = 0.33 self.width = 0.375 self.scale = (0.5, 1.5) self.random_size = (10, 20) self.test_size = (416, 416) self.num_classes = 15 self.exp_name = os.path.split(os.path.realpath(file))[1].split(".")[0] self.enable_mixup = False
def get_data_loader(self, batch_size, is_distributed, no_aug=False):
from yolox.data import (
VOCDetection,
TrainTransform,
YoloBatchSampler,
DataLoader,
InfiniteSampler,
MosaicDetection,
)
dataset = VOCDetection(
data_dir=os.path.join(get_yolox_datadir(), "VOCdevkit"),
image_sets=[('TIAN', 'trainval')],
img_size=self.input_size,
preproc=TrainTransform(
rgb_means=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225),
max_labels=50,
),
)
dataset = MosaicDetection(
dataset,
mosaic=not no_aug,
img_size=self.input_size,
preproc=TrainTransform(
rgb_means=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225),
max_labels=120,
),
degrees=self.degrees,
translate=self.translate,
scale=self.scale,
shear=self.shear,
perspective=self.perspective,
enable_mixup=self.enable_mixup,
)
self.dataset = dataset
if is_distributed:
batch_size = batch_size // dist.get_world_size()
sampler = InfiniteSampler(
len(self.dataset), seed=self.seed if self.seed else 0
)
batch_sampler = YoloBatchSampler(
sampler=sampler,
batch_size=batch_size,
drop_last=False,
input_dimension=self.input_size,
mosaic=not no_aug,
)
dataloader_kwargs = {"num_workers": self.data_num_workers, "pin_memory": True}
dataloader_kwargs["batch_sampler"] = batch_sampler
train_loader = DataLoader(self.dataset, **dataloader_kwargs)
return train_loader
def get_eval_loader(self, batch_size, is_distributed, testdev=False):
from yolox.data import VOCDetection, ValTransform
valdataset = VOCDetection(
data_dir=os.path.join(get_yolox_datadir(), "VOCdevkit"),
image_sets=[('TIAN', 'test')],
img_size=self.test_size,
preproc=ValTransform(
rgb_means=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225),
),
)
if is_distributed:
batch_size = batch_size // dist.get_world_size()
sampler = torch.utils.data.distributed.DistributedSampler(
valdataset, shuffle=False
)
else:
sampler = torch.utils.data.SequentialSampler(valdataset)
dataloader_kwargs = {
"num_workers": self.data_num_workers,
"pin_memory": True,
"sampler": sampler,
}
dataloader_kwargs["batch_size"] = batch_size
val_loader = torch.utils.data.DataLoader(valdataset, **dataloader_kwargs)
return val_loader
def get_evaluator(self, batch_size, is_distributed, testdev=False):
from yolox.evaluators import VOCEvaluator
val_loader = self.get_eval_loader(batch_size, is_distributed, testdev=testdev)
evaluator = VOCEvaluator(
dataloader=val_loader,
img_size=self.test_size,
confthre=self.test_conf,
nmsthre=self.nmsthre,
num_classes=self.num_classes,
)
return evaluator
2021-07-30 16:27:00 | INFO | yolox.core.trainer:132 - Model Summary: Params: 5.04M, Gflops: 6.41 2021-07-30 16:27:03 | INFO | apex.amp.frontend:328 - Selected optimization level O1: Insert automatic casts around Pytorch functions and Tensor methods. 2021-07-30 16:27:03 | INFO | apex.amp.frontend:329 - Defaults for this optimization level are: 2021-07-30 16:27:03 | INFO | apex.amp.frontend:331 - enabled : True 2021-07-30 16:27:03 | INFO | apex.amp.frontend:331 - opt_level : O1 2021-07-30 16:27:03 | INFO | apex.amp.frontend:331 - cast_model_type : None 2021-07-30 16:27:03 | INFO | apex.amp.frontend:331 - patch_torch_functions : True 2021-07-30 16:27:03 | INFO | apex.amp.frontend:331 - keep_batchnorm_fp32 : None 2021-07-30 16:27:03 | INFO | apex.amp.frontend:331 - master_weights : None 2021-07-30 16:27:03 | INFO | apex.amp.frontend:331 - loss_scale : dynamic 2021-07-30 16:27:03 | INFO | apex.amp.frontend:336 - Processing user overrides (additional kwargs that are not None)... 2021-07-30 16:27:03 | INFO | apex.amp.frontend:354 - After processing overrides, optimization options are: 2021-07-30 16:27:03 | INFO | apex.amp.frontend:356 - enabled : True 2021-07-30 16:27:03 | INFO | apex.amp.frontend:356 - opt_level : O1 2021-07-30 16:27:03 | INFO | apex.amp.frontend:356 - cast_model_type : None 2021-07-30 16:27:03 | INFO | apex.amp.frontend:356 - patch_torch_functions : True 2021-07-30 16:27:03 | INFO | apex.amp.frontend:356 - keep_batchnorm_fp32 : None 2021-07-30 16:27:03 | INFO | apex.amp.frontend:356 - master_weights : None 2021-07-30 16:27:03 | INFO | apex.amp.frontend:356 - loss_scale : dynamic 2021-07-30 16:27:03 | INFO | apex.amp.scaler:69 - Warning: multi_tensor_applier fused unscale kernel is unavailable, possibly because apex was installed without --cuda_ext --cpp_ext. Using Python fallback. Original ImportError was: ModuleNotFoundError("No module named 'amp_C'") 2021-07-30 16:27:03 | INFO | yolox.core.trainer:296 - loading checkpoint for fine tuning 2021-07-30 16:27:03 | WARNING | yolox.utils.checkpoint:27 - Shape of head.cls_preds.0.weight in checkpoint is torch.Size([80, 96, 1, 1]), while shape of head.cls_preds.0.weight in model is torch.Size([15, 96, 1, 1]). 2021-07-30 16:27:03 | WARNING | yolox.utils.checkpoint:27 - Shape of head.cls_preds.0.bias in checkpoint is torch.Size([80]), while shape of head.cls_preds.0.bias in model is torch.Size([15]). 2021-07-30 16:27:03 | WARNING | yolox.utils.checkpoint:27 - Shape of head.cls_preds.1.weight in checkpoint is torch.Size([80, 96, 1, 1]), while shape of head.cls_preds.1.weight in model is torch.Size([15, 96, 1, 1]). 2021-07-30 16:27:03 | WARNING | yolox.utils.checkpoint:27 - Shape of head.cls_preds.1.bias in checkpoint is torch.Size([80]), while shape of head.cls_preds.1.bias in model is torch.Size([15]). 2021-07-30 16:27:03 | WARNING | yolox.utils.checkpoint:27 - Shape of head.cls_preds.2.weight in checkpoint is torch.Size([80, 96, 1, 1]), while shape of head.cls_preds.2.weight in model is torch.Size([15, 96, 1, 1]). 2021-07-30 16:27:03 | WARNING | yolox.utils.checkpoint:27 - Shape of head.cls_preds.2.bias in checkpoint is torch.Size([80]), while shape of head.cls_preds.2.bias in model is torch.Size([15]). 2021-07-30 16:27:03 | INFO | yolox.core.trainer:152 - init prefetcher, this might take one minute or less... 2021-07-30 16:27:15 | ERROR | yolox.core.launch:90 - An error has been caught in function 'launch', process 'MainProcess' (27263), thread 'MainThread' (140593167947520): Traceback (most recent call last):
File "tools/train.py", line 125, in
args=(exp, args),
│ └ Namespace(batch_size=64, ckpt='pth/yolox_tiny.pth.tar', devices=1, dist_backend='nccl', dist_url=None, exp_file='exps/yolox_t...
└ ╒══════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════════...
File "tools/train.py", line 104, in main trainer.train() │ └ <function Trainer.train at 0x7fdddb054a70> └ <yolox.core.trainer.Trainer object at 0x7fddd87c7f50>
File "/home/lw/work/YOLOX/yolox/core/trainer.py", line 69, in train self.before_train() │ └ <function Trainer.before_train at 0x7fddd8832560> └ <yolox.core.trainer.Trainer object at 0x7fddd87c7f50>
File "/home/lw/work/YOLOX/yolox/core/trainer.py", line 176, in before_train batch_size=self.args.batch_size, is_distributed=self.is_distributed │ │ │ │ └ False │ │ │ └ <yolox.core.trainer.Trainer object at 0x7fddd87c7f50> │ │ └ 64 │ └ Namespace(batch_size=64, ckpt='pth/yolox_tiny.pth.tar', devices=1, dist_backend='nccl', dist_url=None, exp_file='exps/yolox_t... └ <yolox.core.trainer.Trainer object at 0x7fddd87c7f50>
File "exps/yolox_tiny/yolox_tiny.py", line 117, in get_evaluator val_loader = self.get_eval_loader(batch_size, is_distributed, testdev=testdev) │ │ │ │ └ False │ │ │ └ False │ │ └ 64 │ └ <function Exp.get_eval_loader at 0x7fddd87c5cb0> └ ╒══════════════════╤═════════════════════════════════════════════════════════════════════════════════════════════════════════...
File "exps/yolox_tiny/yolox_tiny.py", line 102, in get_eval_loader sampler = torch.utils.data.SequentialSampler(valdataset) └ <yolox.data.datasets.voc.VOCDetection object at 0x7fddb5fe0c50>
NameError: name 'torch' is not defined