keras-team / keras-hub

Pretrained model hub for Keras 3
Apache License 2.0
804 stars 243 forks source link

keras.utils.plot_model produces error on Linux Fedora #1966

Closed ashep29 closed 1 week ago

ashep29 commented 3 weeks ago

The following command works on standard Google Colab notebook: keras.utils.plot_model(model,"cifar_10.png",show_shapes=True)

It does not run on the following system, producing the error below:

System info: NAME="Rocky Linux" VERSION="8.10 (Green Obsidian)" ID="rocky" ID_LIKE="rhel centos fedora" VERSION_ID="8.10" PLATFORM_ID="platform:el8"

Python 3.11.0rcl


FileNotFoundError Traceback (most recent call last) File ~/.local/lib/python3.11/site-packages/pydot/core.py:1799, in Dot.create(self, prog, format, encoding) 1798 try: -> 1799 stdout_data, stderr_data, process = call_graphviz( 1800 program=prog, 1801 arguments=arguments, 1802 working_dir=tmp_dir, 1803 ) 1804 except OSError as e:

File ~/.local/lib/python3.11/site-packages/pydot/core.py:222, in call_graphviz(program, arguments, working_dir, kwargs) 220 program_with_args = [program] + arguments --> 222 process = subprocess.Popen( 223 program_with_args, 224 env=env, 225 cwd=working_dir, 226 shell=False, 227 stderr=subprocess.PIPE, 228 stdout=subprocess.PIPE, 229 kwargs, 230 ) 231 stdout_data, stderr_data = process.communicate()

File /usr/lib/python3.11/subprocess.py:1022, in Popen.init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group) 1019 self.stderr = io.TextIOWrapper(self.stderr, 1020 encoding=encoding, errors=errors) -> 1022 self._execute_child(args, executable, preexec_fn, close_fds, 1023 pass_fds, cwd, env, 1024 startupinfo, creationflags, shell, 1025 p2cread, p2cwrite, 1026 c2pread, c2pwrite, 1027 errread, errwrite, 1028 restore_signals, 1029 gid, gids, uid, umask, 1030 start_new_session, process_group) 1031 except: 1032 # Cleanup if the child failed starting.

File /usr/lib/python3.11/subprocess.py:1899, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session, process_group) 1898 err_msg = os.strerror(errno_num) -> 1899 raise child_exception_type(errno_num, err_msg, err_filename) 1900 raise child_exception_type(err_msg)

FileNotFoundError: [Errno 2] No such file or directory: 'dot'

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last) File /usr/local/lib/python3.11/dist-packages/keras/src/utils/model_visualization.py:37, in check_graphviz() 34 try: 35 # Attempt to create an image of a blank graph 36 # to check the pydot/graphviz installation. ---> 37 pydot.Dot.create(pydot.Dot()) 38 return True

File ~/.local/lib/python3.11/site-packages/pydot/core.py:1808, in Dot.create(self, prog, format, encoding) 1807 args[1] = f'"{prog}" not found in path.' -> 1808 raise OSError(*args) 1809 else:

FileNotFoundError: [Errno 2] "dot" not found in path.

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last) Cell In[20], line 1 ----> 1 keras.utils.plot_model(model, "cifar_10.png",show_shapes=True) #use show_shapes=True if you want to see input/output shapes

File /usr/local/lib/python3.11/dist-packages/keras/src/utils/model_visualization.py:430, in plot_model(model, to_file, show_shapes, show_dtype, show_layer_names, rankdir, expand_nested, dpi, show_layer_activations, show_trainable, **kwargs) 428 else: 429 raise ImportError(message) --> 430 if not check_graphviz(): 431 message = ( 432 "You must install graphviz " 433 "(see instructions at https://graphviz.gitlab.io/download/) " 434 "for plot_model to work." 435 ) 436 if "IPython.core.magics.namespace" in sys.modules: 437 # We don't raise an exception here in order to avoid crashing 438 # notebook tests where graphviz is not available.

File /usr/local/lib/python3.11/dist-packages/keras/src/utils/model_visualization.py:39, in check_graphviz() 37 pydot.Dot.create(pydot.Dot()) 38 return True ---> 39 except (OSError, pydot.InvocationException): 40 return False

AttributeError: module 'pydot' has no attribute 'InvocationException'

SamanehSaadat commented 2 weeks ago

Hi @ashep29

This Stack overflow post recommends pinning pinning your pydot version to 2.0.0 (pip install pydot==2.0.0). Have you tried this?

If an issue is not reproducible on colab, it would be very hard for us to debug.