iprog4u

iprog4u

Machine Learning in Elixir: Chapter 6 Axon.Display.as_table does not work (Page 133)

Please guide me in the right direction. I am able to get .as_graph() to display the model correctly

Axon.Display.as_graph(model, template)

however when I try to run .as_table() I get an error (CAUTION: wall of error text follows):

Axon.Display.as_table(model, template)
|> IO.puts

** (FunctionClauseError) no function clause matching in Axon.Display.do_axon_to_rows/6    
    
    The following arguments were given to Axon.Display.do_axon_to_rows/6:
    
        # 1
        %Axon.Node{
          id: 5,
          name: #Function<194.57606554/2 in Axon.name/2>,
          mode: :both,
          parent: [4],
          parameters: [],
          args: [:layer],
          op: :softmax,
          policy: #Axon.MixedPrecision.Policy<>,
          hooks: [],
          opts: [],
          global_options: [],
          op_name: :softmax,
          meta: %{},
          stacktrace: [
            {Axon, :layer, 3, [file: ~c"lib/axon.ex", line: 346]},
            {:elixir, :eval_external_handler, 3, [file: ~c"src/elixir.erl", line: 388]},
            {:erl_eval, :do_apply, 7, [file: ~c"erl_eval.erl", line: 919]},
            {:erl_eval, :expr, 6, [file: ~c"erl_eval.erl", line: 663]},
            {:elixir, :eval_forms, 4, [file: ~c"src/elixir.erl", line: 366]},
            {Module.ParallelChecker, :verify, 1, [file: ~c"lib/module/parallel_checker.ex", line: 120]}
          ]
        }
    
        # 2
        %{
          1 => %Axon.Node{
            id: 1,
            name: #Function<195.57606554/2 in Axon.name/2>,
            mode: :both,
            parent: [],
            parameters: [],
            args: [],
            op: :input,
            policy: #Axon.MixedPrecision.Policy<>,
            hooks: [],
            opts: [shape: {nil, 748}, optional: false],
            global_options: [],
            op_name: :input,
            meta: nil,
            stacktrace: [
              {Axon, :layer, 3, [file: ~c"lib/axon.ex", line: 346]},
              {:elixir, :eval_external_handler, 3, [file: ~c"src/elixir.erl", line: 388]},
              {:erl_eval, :do_apply, 7, [file: ~c"erl_eval.erl", line: 919]},
              {:erl_eval, :expr_list, 7, [file: ~c"erl_eval.erl", line: 1207]},
              {:erl_eval, :expr, 6, [file: ~c"erl_eval.erl", line: 625]},
              {:erl_eval, :expr_list, 7, [file: ~c"erl_eval.erl", line: 1207]}
            ]
          },
          2 => %Axon.Node{
            id: 2,
            name: #Function<194.57606554/2 in Axon.name/2>,
            mode: :both,
            parent: [1],
            parameters: [
              %Axon.Parameter{
                name: "kernel",
                template: #Function<485.57606554/1 in Axon.shape_fun/2>,
                shape: nil,
                initializer: #Function<3.47872556/3 in Axon.Initializers.glorot_uniform/1>,
                children: nil,
                type: {:f, 32},
                frozen: false,
                kind: :parameter
              },
              %Axon.Parameter{
                name: "bias",
                template: #Function<485.57606554/1 in Axon.shape_fun/2>,
                shape: nil,
                initializer: #Function<23.47872556/2 in Axon.Initializers.zeros/0>,
                children: nil,
                type: {:f, 32},
                frozen: false,
                kind: :parameter
              }
            ],
            args: [:layer, :parameter, :parameter],
            op: :dense,
            policy: #Axon.MixedPrecision.Policy<>,
            hooks: [],
            opts: [],
            global_options: [],
            op_name: :dense,
            meta: %{use_bias: true, units: 128},
            stacktrace: [
              {Axon, :layer, 3, [file: ~c"lib/axon.ex", line: 346]},
              {Axon, :dense, 3, [file: ~c"lib/axon.ex", line: 877]},
              {:elixir, :eval_external_handler, 3, [file: ~c"src/elixir.erl", line: 388]},
              {:erl_eval, :do_apply, 7, [file: ~c"erl_eval.erl", line: 919]},
              {:erl_eval, :expr_list, 7, [file: ~c"erl_eval.erl", line: 1207]},
              {:erl_eval, :expr, 6, [file: ~c"erl_eval.erl", line: 625]}
            ]
          },
          3 => %Axon.Node{
            id: 3,
            name: #Function<194.57606554/2 in Axon.name/2>,
            mode: :both,
            parent: [2],
            parameters: [],
            args: [:layer],
            op: :relu,
            policy: #Axon.MixedPrecision.Policy<>,
            hooks: [],
            opts: [],
            global_options: [],
            op_name: :relu,
            meta: %{},
            stacktrace: [
              {Axon, :layer, 3, [file: ~c"lib/axon.ex", line: 346]},
              {:elixir, :eval_external_handler, 3, [file: ~c"src/elixir.erl", line: 388]},
              {:erl_eval, :do_apply, 7, [file: ~c"erl_eval.erl", line: 919]},
              {:erl_eval, :expr_list, 7, [file: ~c"erl_eval.erl", line: 1207]},
              {:erl_eval, :expr, 6, [file: ~c"erl_eval.erl", line: 625]},
              {:erl_eval, :expr, 6, [file: ~c"erl_eval.erl", line: 663]}
            ]
          },
          4 => %Axon.Node{
            id: 4,
            name: #Function<194.57606554/2 in Axon.name/2>,
            mode: :both,
            parent: [3],
            parameters: [
              %Axon.Parameter{
                name: "kernel",
                template: #Function<485.57606554/1 in Axon.shape_fun/2>,
                shape: nil,
                initializer: #Function<3.47872556/3 in Axon.Initializers.glorot_uniform/1>,
                children: nil,
                type: {:f, 32},
                frozen: false,
                kind: :parameter
              },
              %Axon.Parameter{
                name: "bias",
                template: #Function<485.57606554/1 in Axon.shape_fun/2>,
                shape: nil,
                initializer: #Function<23.47872556/2 in Axon.Initializers.zeros/0>,
                children: nil,
                type: {:f, 32},
                frozen: false,
                kind: :parameter
              }
            ],
            args: [:layer, :parameter, :parameter],
            op: :dense,
            policy: #Axon.MixedPrecision.Policy<>,
            hooks: [],
            opts: [],
            global_options: [],
            op_name: :dense,
            meta: %{use_bias: true, units: 10},
            stacktrace: [
              {Axon, :layer, 3, [file: ~c"lib/axon.ex", line: 346]},
              {Axon, :dense, 3, [file: ~c"lib/axon.ex", line: 877]},
              {:elixir, :eval_external_handler, 3, [file: ~c"src/elixir.erl", line: 388]},
              {:erl_eval, :do_apply, 7, [file: ~c"erl_eval.erl", line: 919]},
              {:erl_eval, :expr, 6, [file: ~c"erl_eval.erl", line: 663]},
              {:elixir, :eval_forms, 4, [file: ~c"src/elixir.erl", line: 366]}
            ]
          },
          5 => %Axon.Node{
            id: 5,
            name: #Function<194.57606554/2 in Axon.name/2>,
            mode: :both,
            parent: [4],
            parameters: [],
            args: [:layer],
            op: :softmax,
            policy: #Axon.MixedPrecision.Policy<>,
            hooks: [],
            opts: [],
            global_options: [],
            op_name: :softmax,
            meta: %{},
            stacktrace: [
              {Axon, :layer, 3, [file: ~c"lib/axon.ex", line: 346]},
              {:elixir, :eval_external_handler, 3, [file: ~c"src/elixir.erl", line: 388]},
              {:erl_eval, :do_apply, 7, [file: ~c"erl_eval.erl", line: 919]},
              {:erl_eval, :expr, 6, [file: ~c"erl_eval.erl", line: 663]},
              {:elixir, :eval_forms, 4, [file: ~c"src/elixir.erl", line: 366]},
              {Module.ParallelChecker, :verify, 1, [file: ~c"lib/module/parallel_checker.ex", line: 120]}
            ]
          }
        }
    
        # 3
        #Nx.Tensor<
          f32[1][784]
          Nx.TemplateBackend
        >
    
        # 4
        %{}
    
        # 5
        %{}
    
        # 6
        %{num_params: 0, total_param_byte_size: 0}
    
    Attempted function clauses (showing 2 out of 2):
    
        defp do_axon_to_rows(%Axon.Node{id: id, op: structure, op_name: :container, parent: [parents], name: name_fn}, nodes, templates, cache, op_counts, model_info)
        defp do_axon_to_rows(%Axon.Node{
      id: id,
      parent: parents,
      parameters: params,
      name: name_fn,
      opts: opts,
      policy: %{params: {_, bitsize}},
      op_name: op_name
    }, nodes, templates, cache, op_counts, model_info)
    
    (axon 0.7.0) lib/axon/display.ex:93: Axon.Display.do_axon_to_rows/6
    (axon 0.7.0) lib/axon/display.ex:85: Axon.Display.axon_to_rows/6
    (axon 0.7.0) lib/axon/display.ex:39: Axon.Display.as_table/2
    #cell:r744jk7wwgcawf6v:2: (file)

Perhaps not hyper important as the graph contains the same info but it is nice how the table has the labels.

Marked As Solved

iprog4u

iprog4u

Removing specific versions or updating to the latest available version corrected the issue for me. Pol Valente was kind enough to update the Axon lib, thanks Pol!

Mix.install([
  :axon,
  :nx,
  :exla,
  :kino,
  :table_rex,
  :scidata
])

Nx.default_backend(EXLA.Backend)

Axon.Display.as_table(model, template)
|> IO.puts()
+------------------------------------------------------------------------------------------------------------------+
|                                                      Model                                                       |
+=======================+===============================+==============+===================+=======================+
| Layer                 | Input Shape                   | Output Shape | Options           | Parameters            |
+=======================+===============================+==============+===================+=======================+
| images ( input )      | %{}                           | f32[1][784]  | shape: {nil, 784} |                       |
|                       |                               |              | optional: false   |                       |
+-----------------------+-------------------------------+--------------+-------------------+-----------------------+
| dense_0 ( dense )     | %{"images" => "f32[1][784]"}  | f32[1][128]  |                   | kernel: f32[784][128] |
|                       |                               |              |                   | bias: f32[128]        |
+-----------------------+-------------------------------+--------------+-------------------+-----------------------+
| relu_0 ( relu )       | %{"dense_0" => "f32[1][128]"} | f32[1][128]  |                   |                       |
+-----------------------+-------------------------------+--------------+-------------------+-----------------------+
| dense_1 ( dense )     | %{"relu_0" => "f32[1][128]"}  | f32[1][10]   |                   | kernel: f32[128][10]  |
|                       |                               |              |                   | bias: f32[10]         |
+-----------------------+-------------------------------+--------------+-------------------+-----------------------+
| softmax_0 ( softmax ) | %{"dense_1" => "f32[1][10]"}  | f32[1][10]   |                   |                       |
+-----------------------+-------------------------------+--------------+-------------------+-----------------------+
Total Parameters: 101770
Total Parameters Memory: 407.08 kilobytes

Where Next?

Popular Pragmatic Bookshelf topics Top

simonpeter
When I try the command to create a pair of migration files I get an error. user=&gt; (create-migration "guestbook") Execution error (Ill...
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
jgchristopher
“The ProductLive.Index template calls a helper function, live_component/3, that in turn calls on the modal component. ” Excerpt From: Br...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
PragmaticBookshelf
Tailwind CSS is an exciting new CSS framework that allows you to design your site by composing simple utility classes to create complex e...
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
New
PragmaticBookshelf
Use advanced functional programming principles, practical Domain-Driven Design techniques, and production-ready Elixir code to build scal...
New

Sub Categories: