LivingMatterLab / CANN

When using, please cite "A new family of Constitutive Artificial Neural Networks towards automated model discovery", CMAME, https://doi.org/10.1016/j.cma.2022.115731 and the relevant other papers from this repo
39 stars 17 forks source link

Problem running the code #1

Closed juanpg4 closed 4 months ago

juanpg4 commented 10 months ago

Hi, when I run the CANN4brain_main.py code I get the following error:

Traceback (most recent call last): File "CANN4brain_main.py", line 304, in model_given, history = Compile_and_fit(model_given, input_train, output_train, epochs, path_checkpoint, sample_weights) File "CANN4brain_main.py", line 142, in Compile_and_fit history = model_given.fit(input_train, File "/home/jperg/venv/lib/python3.8/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None File "/tmp/autograph_generated_filega2ntee1.py", line 15, in tftrainfunction retval = ag.converted_call(ag__.ld(step_function), (ag.ld(self), ag__.ld(iterator)), None, fscope) TypeError: in user code:

File "/home/jperg/venv/lib/python3.8/site-packages/keras/src/engine/training.py", line 1338, in train_function  *
    return step_function(self, iterator)
File "/home/jperg/venv/lib/python3.8/site-packages/keras/src/engine/training.py", line 1322, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/home/jperg/venv/lib/python3.8/site-packages/keras/src/engine/training.py", line 1303, in run_step  **
    outputs = model.train_step(data)
File "/home/jperg/venv/lib/python3.8/site-packages/keras/src/engine/training.py", line 1085, in train_step
    return self.compute_metrics(x, y, y_pred, sample_weight)
File "/home/jperg/venv/lib/python3.8/site-packages/keras/src/engine/training.py", line 1179, in compute_metrics
    self.compiled_metrics.update_state(y, y_pred, sample_weight)
File "/home/jperg/venv/lib/python3.8/site-packages/keras/src/engine/compile_utils.py", line 577, in update_state
    self.build(y_pred, y_true)
File "/home/jperg/venv/lib/python3.8/site-packages/keras/src/engine/compile_utils.py", line 483, in build
    self._metrics = tf.__internal__.nest.map_structure_up_to(

TypeError: If shallow structure is a sequence, input must also be a sequence. Input has type: <class 'tensorflow.python.framework.ops.Tensor'>.

does anyone else have this problem or know how to solve it?

juanpg4 commented 10 months ago

It is when te case: Region: CC | Fitting Mode: TC is running

yyqml commented 10 months ago

I have the same problem. Have you solved it?

skylerstpierre commented 9 months ago

For the case of fitting tension, compression, and shear simultaneously please try using double brackets like in the Jupyter Notebook for the stretch-based brain model: input_train = [[lam_ut], [gamma_ss]] output_train = [[P_ut], [P_ss]] sample_weights_tc = weighing_TC sample_weights_ss = np.array([1.0]*gamma_ss.shape[0]) sample_weights = [[sample_weights_tc], [sample_weights_ss]]

The Jupyter notebook contains the invariant-based model as well, so please try using that instead of the python code and see if that solves your issues. The Graz workshop folder contains more explicit instructions if you have not worked with Jupyter notebooks before. In general, we have found that different OS and different package versions influence whether there are issues with running the python code, so we developed the notebook to make the code more readily accessible.