Issue while running train_model in C3_W1 Assignment, Please help

I am facing an error when trying to run Exercise 6 (in train_model) in week 1 assignment,

following is the error:


AttributeError Traceback (most recent call last)
in
2 # Take a look on how the eval_task is inside square brackets and
3 # take that into account for you train_model implementation
----> 4 training_loop = train_model(model, train_task, [eval_task], 100, output_dir_expand)

in train_model(classifier, train_task, eval_task, n_steps, output_dir)
20 eval_tasks=eval_task[0], # The evaluation task
21 output_dir=output_dir, # The output directory
—> 22 random_seed=31 # Do not modify this random seed in order to ensure reproducibility and for grading purposes.
23 )
24

/opt/conda/lib/python3.7/site-packages/trax/supervised/training.py in init(self, model, tasks, eval_model, eval_tasks, output_dir, checkpoint_at, checkpoint_low_metric, checkpoint_high_metric, permanent_checkpoint_at, eval_at, which_task, n_devices, random_seed, loss_chunk_size, use_memory_efficient_trainer, adasum, callbacks)
241 # NOTE: If random_seed is None then self._rng will be different on
242 # different hosts, leading to different weights on the different hosts.
→ 243 self._batch_signature = shapes.signature(tasks[0].sample_batch)
244 self._model.rng = self.new_rng()
245 # In the memory-efficient case, we initialize in init_trainer.

/opt/conda/lib/python3.7/site-packages/trax/shapes.py in signature(obj)
95 “”"
96 if isinstance(obj, (list, tuple)):
—> 97 output = tuple(signature(x) for x in obj)
98 return output if isinstance(obj, tuple) else list(output)
99 elif isinstance(obj, dict):

/opt/conda/lib/python3.7/site-packages/trax/shapes.py in (.0)
95 “”"
96 if isinstance(obj, (list, tuple)):
—> 97 output = tuple(signature(x) for x in obj)
98 return output if isinstance(obj, tuple) else list(output)
99 elif isinstance(obj, dict):

/opt/conda/lib/python3.7/site-packages/trax/shapes.py in signature(obj)
95 “”"
96 if isinstance(obj, (list, tuple)):
—> 97 output = tuple(signature(x) for x in obj)
98 return output if isinstance(obj, tuple) else list(output)
99 elif isinstance(obj, dict):

/opt/conda/lib/python3.7/site-packages/trax/shapes.py in (.0)
95 “”"
96 if isinstance(obj, (list, tuple)):
—> 97 output = tuple(signature(x) for x in obj)
98 return output if isinstance(obj, tuple) else list(output)
99 elif isinstance(obj, dict):

/opt/conda/lib/python3.7/site-packages/trax/shapes.py in signature(obj)
100 return {k: signature(v) for (k, v) in obj.items()}
101 else:
→ 102 return ShapeDtype(obj.shape, obj.dtype)
103
104

AttributeError: ‘int’ object has no attribute ‘shape’

In the link above, you can see that eval_task takes a list. So your answer should be not eval_tasks=eval_task[0] but simply eval_tasks=eval_task

@vsnupoudel @sai_trinath_dubba

If I use

eval_tasks=eval_task

I get the following error:
TypeError: Incompatible shapes for dot: got (16, 17) and (15, 2).

So that is not resolving.

Anyway I am not understanding this sentence in the notes just above train_model cell. Can any of you explain it?

the eval_task is passed as a list explicitly, so take that into account in the implementation of your train_model function.

This sentence appears to be irrelevant.

For me, have to ensure that the mean_layer in UNQ_C5 (def classifier) is the mean of columns.

Hope this helps you too…

ThanQ…

1 Like

Please check all the place where you have numpy.dot() or np.dot() function. Here the matrix multiplication is not happening, as the matrices are incompatible for matrix multiplication.

Glad that the issue is solved.

I used eval_tasks instead of eval_task and the grader rejected all my answers saying “Grader found global variables inside graded fuctions. Please avoid using global variables in your functions.”
Can anyone help me with this issue of defining eval_task as a list?
Thanks in advance for helping.