I run this code in windows 10,and set the environment as the instruction,but always appear the erro:AttributeError: type object 'StateTSP' has no attribute 'initialize'.can u help me with the issue.
Hi,
For me to help me you have to be a bit more precise as to what exactly you did and which command you run to get this output. initialize
should exist in StateTSP
, see https://github.com/wouterkool/attention-learn-to-route/blob/a6d0623b24b74e4d73f2dc05eb39100835c5bf6e/problems/tsp/state_tsp.py#L43 so maybe you can debug what is the problem from there?
I'sorry but I meet the same problem when trying "python run.py --graph_size 20 --baseline rollout --run_name 'tsp20_rollout' ", can u help me?
Traceback (most recent call last):
File "run.py", line 172, in
run(get_options())
File "run.py", line 104, in run
baseline = RolloutBaseline(model, problem, opts)
File "/home/jinHM/fanyu/attention-learn-to-route-master/reinforce_baselines.py", line 151, in init
self._update_model(model, epoch)
File "/home/jinHM/fanyu/attention-learn-to-route-master/reinforce_baselines.py", line 171, in _update_model
self.bl_vals = rollout(self.model, self.dataset, self.opts).cpu().numpy()
File "/home/jinHM/fanyu/attention-learn-to-route-master/train.py", line 43, in rollout
in tqdm(DataLoader(dataset, batch_size=opts.eval_batch_size), disable=opts.no_progress_bar)
File "/home/jinHM/fanyu/attention-learn-to-route-master/train.py", line 42, in
for bat
File "/home/jinHM/fanyu/attention-learn-to-route-master/train.py", line 37, in eval_model_bat
cost, _ = model(move_to(bat, opts.device))
File "/home/jinHM/anaconda3/envs/mdvrp/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/jinHM/anaconda3/envs/mdvrp/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 152, in forward
outputs = self.parallel_apply(replicas, inputs, kwargs)
File "/home/jinHM/anaconda3/envs/mdvrp/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 162, in parallel_apply
return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
File "/home/jinHM/anaconda3/envs/mdvrp/lib/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 85, in parallel_apply
output.reraise()
File "/home/jinHM/anaconda3/envs/mdvrp/lib/python3.6/site-packages/torch/_utils.py", line 394, in reraise
raise self.exc_type(msg)
AttributeError: Caught AttributeError in replica 0 on device 0.
Original Traceback (most recent call last):
File "/home/jinHM/anaconda3/envs/mdvrp/lib/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 60, in _worker
output = module(*input, **kwargs)
File "/home/jinHM/anaconda3/envs/mdvrp/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/jinHM/fanyu/attention-learn-to-route-master/nets/attention_model.py", line 138, in forward
_log_p, pi = self._inner(input, embeddings)
File "/home/jinHM/fanyu/attention-learn-to-route-master/nets/attention_model.py", line 230, in _inner
state = self.problem.make_state(input)
File "/home/jinHM/fanyu/attention-learn-to-route-master/problems/tsp/problem_tsp.py", line 33, in make_state
return StateTSP.initialize(*args, **kwargs)
AttributeError: type object 'StateTSP' has no attribute 'initialize'
Judging from your output, maybe it has something to do with running on multiple GPUs. Can you try on a single GPU? E.g. run 'CUDA_VISIBLE_DEVICES=0 python run.py ...'. Otherwise, maybe you can help debug why this error comes up, as the class StateTSP has the method initialize (see my earlier response)? Thanks!
I'sorry but I meet the same problem when trying "python run.py --graph_size 100 --load_path pretrained/tsp_100/epoch-99.pt" in ubuntu 18.04, can u help me?
Traceback (most recent call last):
File "run.py", line 172, in
run(get_options())
File "run.py", line 167, in run
opts
File "/home/ls/PycharmProjects/attention-learn-to-route-master/train.py", line 95, in train_epoch
opts
File "/home/ls/PycharmProjects/attention-learn-to-route-master/train.py", line 143, in train_batch
cost, log_likelihood = model(x)
File "/home/ls/anaconda3/envs/ls/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/ls/PycharmProjects/attention-learn-to-route-master/nets/attention_model.py", line 138, in forward
_log_p, pi = self._inner(input, embeddings)
File "/home/ls/PycharmProjects/attention-learn-to-route-master/nets/attention_model.py", line 230, in _inner
state = self.problem.make_state(input)
File "/home/ls/PycharmProjects/attention-learn-to-route-master/problems/tsp/problem_tsp.py", line 33, in make_state
return StateTSP.initialize(*args, **kwargs)
AttributeError: type object 'StateTSP' has no attribute 'initialize'
Hi! I'm sorry to hear it's causing you trouble. Which version of Python are you using? See my earlier response, initialize
should be a static method of StateTSP
, see https://github.com/wouterkool/attention-learn-to-route/blob/a6d0623b24b74e4d73f2dc05eb39100835c5bf6e/problems/tsp/state_tsp.py#L43, so maybe you can help me and debug why it is missing?