I'm trying to use the plot_model function with TensorFlow to plot my model and save it to a file on Ubuntu 22.04. Pycharm 2024.1.3. python 3.12. Tensorflow 2.16.1.I assume Pydotplus and Graphviz are installed properly, or there is something I miss.The file has been created, but it is broken (0 bytes) and can't be opened.
The scripts ends with the error:Traceback (most recent call last):File "/home/linuxpc/PycharmProjects/Semen_project/temp.py", line 314, in create_model(model_parameters=model_par)File "/home/linuxpc/PycharmProjects/Semen_project/temp.py", line 224, in create_modeltf.keras.utils.plot_model(File "/home/linuxpc/PycharmProjects/Semen_project/.venv/lib/python3.12/site-packages/keras/src/utils/model_visualization.py", line 456, in plot_modeldot.write(to_file, format=extension)File "/home/linuxpc/PycharmProjects/Semen_project/.venv/lib/python3.12/site-packages/pydotplus/graphviz.py", line 1919, in writefobj.write(self.create(prog, format))^^^^^^^^^^^^^^^^^^^^^^^^^File "/home/linuxpc/PycharmProjects/Semen_project/.venv/lib/python3.12/site-packages/pydotplus/graphviz.py", line 2031, in createraise InvocationException(pydotplus.graphviz.InvocationException: Program terminated with status: -6. stderr follows: failed at node 716[0]dot: maze.c:311: chkSgraph: Assertion `np->cells[0]' failed
The model creation part of the script:gobal_input_layer = tf.keras.layers.Input(shape=layer_size[0]['1'][0])
"""Model_1 to detect fibers"""for lnum, layer in enumerate(layer_size[0]): if lnum == 0: for vnum, val in enumerate(layer_size[0][layer]): if vnum == 0: layer = tf.keras.layers.Identity()(gobal_input_layer) else: layer = tf.keras.layers.Dense(val[0], activation="sigmoid")(layer) if len(val) == 2: layer = tf.keras.layers.Dropout(val[1])(layer) output_layer = tf.keras.layers.Dense(2, activation="sigmoid")(layer) intermediate = tf.keras.layers.Reshape((2, 1), input_shape=(1, 2))(output_layer) first_half = tf.keras.layers.Cropping1D(cropping=(0, 1))(intermediate) first_half = tf.keras.layers.Reshape((1,), input_shape=(1, 1))(first_half) second_half = tf.keras.layers.Cropping1D(cropping=(0, 1))(intermediate) second_half = tf.keras.layers.Reshape((1,), input_shape=(1, 1))(second_half) elif lnum == 1: for vnum, val in enumerate(layer_size[0][layer]): if vnum == 0: layer_2 = tf.keras.layers.Concatenate()([gobal_input_layer, second_half]) layer_2 = tf.keras.layers.Identity()(layer_2) else: layer_2 = tf.keras.layers.Dense(val[0], activation="sigmoid")(layer_2) if len(val) == 2: layer_2 = tf.keras.layers.Dropout(val[1])(layer_2) output_layer_2 = tf.keras.layers.Dense(2, activation="sigmoid")(layer_2) else: raise ValueError(f"The length of layers is than 2")outputs = tf.keras.layers.Concatenate()([output_layer_2, output_layer])outputs = tf.keras.layers.Identity()(outputs)model = tf.keras.Model(inputs=gobal_input_layer, outputs=outputs)model.name = model_parameters["model_name"]return model
I've tried pydot, pydotplus, and pydot-ng (installed from pip) - the result is the same. Graphviz is installed either via "sudo apt install graphviz" or "pip install graphviz". The extension of the file doesn't matter - I've tried jpg, png, pdf. After graphviz insallation the PC has been rebooted.
The last line of the Traceback error doesn't give me anything, and I'm stuck. I see that something is wrong with dot and it generates status [-6], but what it is, I don't know. I suppose the is the problem with generating image or/and writing it to the file (because file is empty after crash). Another thought is incapability of one or more layer or model itself to traslated to dot.
Can anyone help me solve the problem, or suggest where I should start to dig in at least?I would appreciate any help anyone can provide.