philipbrown / handwritten-digits

Handwritten digit recognition in Elixir
45 stars 13 forks source link

MatchError no match of right hand side value: %Evision.Mat #2

Closed dominik-geiling closed 1 year ago

dominik-geiling commented 1 year ago

With the following dependencies: {:phoenix, "~> 1.6.5"}, {:phoenix_html, "~> 3.0"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, {:phoenix_live_view, "~> 0.17.5"}, {:floki, ">= 0.30.0", only: :test}, {:phoenix_live_dashboard, "~> 0.6"}, {:esbuild, "~> 0.3", runtime: Mix.env() == :dev}, {:swoosh, "~> 1.3"}, {:telemetry_metrics, "~> 0.6"}, {:telemetry_poller, "~> 1.0"}, {:gettext, "~> 0.18"}, {:jason, "~> 1.2"}, {:plug_cowboy, "~> 2.5"}, {:tailwind, "~> 0.1", runtime: Mix.env() == :dev}, {:axon, "~> 0.3.0"}, {:scidata, "~> 0.1.5"}, {:evision, "~> 0.1.0-dev", github: "cocoa-xu/evision", branch: "main"}

and after clicking "Predict" on the frontend, I get the following error:

[error] GenServer #PID<0.2059.0> terminating ** (MatchError) no match of right hand side value: %Evision.Mat{channels: 1, dims: 2, type: {:u, 8}, raw_type: 0, shape: {384, 384}, ref: #Reference<0.2647608870.945422355.36505>} (digits 0.1.0) lib/digits/model.ex:65: Digits.Model.predict/1 (digits 0.1.0) lib/digits_web/live/page_live.ex:54: DigitsWeb.PageLive.handle_event/3 (phoenix_live_view 0.17.9) lib/phoenix_live_view/channel.ex:382: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3 (telemetry 1.1.0) /Users/user/xxx/xxx/handwritten-digits/deps/telemetry/src/telemetry.erl:320: :telemetry.span/3 (phoenix_live_view 0.17.9) lib/phoenix_live_view/channel.ex:215: Phoenix.LiveView.Channel.handle_info/2 (stdlib 4.1.1) gen_server.erl:1123: :gen_server.try_dispatch/4 (stdlib 4.1.1) gen_server.erl:1200: :gen_server.handle_msg/6 (stdlib 4.1.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3 Last message: %Phoenix.Socket.Message{topic: "lv:phx-FzRxEyuOZneo9-tE", event: "event", payload: %{"event" => "image", "type" => "hook", "value" => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYAAAAGACAYAAACkx7W/AAAd40lEQVR4Xu3dCZBsVXkH8IfRKBoDrkgEF5SISwyKYimW4i5LFIi4BNEiuCakXMEFFBQ3FqPlUhFLDSpRoyJuqMGooBXKJdEQE3cUxQU1KliKJCaS/9UHAeG9/u7M7e57+/y6asrHm++e853fOd7/m+mZ7i02eBAgQIBAkwJbNLlqiyZAgACBDQLAISBAgECjAgKg0Y23bAIECAgAZ4AAAQKNCgiARjfesgkQICAAnAECBAg0KiAAGt14yyZAgIAAcAYIECDQqIAAaHTjLZsAAQICwBkgQIBAowICoNGNt2wCBAgIAGeAAAECjQoIgEY33rIJECAgAJwBAgQINCogABrdeMsmQICAAHAGCBAg0KiAAGh04y2bAAECAsAZIECAQKMCAqDRjbdsAgQICABngAABAo0KCIBGN96yCRAgIACcAQIECDQqIAAa3XjLJkCAgABwBggQINCogABodOMtmwABAgLAGSBAgECjAgKg0Y23bAIECAgAZ4AAAQKNCgiARjfesgkQICAAnAECBAg0KiAAGt14yyZAgIAAcAYIECDQqIAAaHTjLZsAAQICwBkgQIBAowICoNGNt2wCBAgIAGeAAAECjQoIgEY33rIJECAgAJwBAgQINCogABrdeMsmQICAAHAGCBAg0KiAAGh04y2bAAECAsAZIECAQKMCAqDRjbdsAgQICABngAABAo0KCIBGN96yCRAgIACcAQIECDQqIAAa3XjLJkCAgABwBggQINCogABodOMtmwABAgLAGSBAgECjAgKg0Y23bAIECAgAZ4AAAQKNCgiARjfesgkQICAAnAECBAg0KiAAGt14yyZAgIAAcAYIECDQqIAAaHTjLZsAAQICwBkgQIBAowICoNGNt2wCBAgIAGeAAAECjQoIgEY33rIJECAgAJwBAgQINCogABrdeMsmQICAAHAGCBAg0KiAAGh04y2bAAECAsAZIECAQKMCAqDRjbdsAgQICABngAABAo0KCIBGN96yCRAgIACcAQIECDQqIAAa3XjLJkCAgABwBggQINCogABodOMtmwABAgLAGSBAgECjAgKg0Y23bAIECAgAZ4AAAQKNCgiARjfesgkQICAAnAECBAg0KiAAGt14yyZAgIAAcAYIECDQqIAAaHTjLZsAAQICwBkgQIBAowICoNGNt2wCBAgIAGeAAAECjQoIgEY33rIJECAgAJwBAgQINCogABrdeMsmQICAAHAGCBAg0KiAAGh04y2bAAECAsAZIECAQKMCAqDRjbdsAgQICABngAABAo0KCIBGN96yCRAgIACcAQIECDQqIAAa3XjLJkCAgABwBggQINCogABodOMtmwABAgLAGSBAgECjAgKg0Y23bAIECAgAZ4AAAQKNCgiARjfesgkQICAAnAECBAg0KiAAGt14yyZAgIAAcAYIECDQqIAAaHTjLZsAAQICwBkgQIBAowICoNGNt2wCBAgIAGeAAAECjQoIgEY33rIJECAgAJwBAgQINCogABrdeMsmQICAAHAGCBAg0KiAAGh04y2bAAECAsAZIECAQKMCAqDRjbdsAgQICABngAABAo0KCIBGN96yCRAgIACcAQIECDQqIAAa3XjLJkCAgABwBggQINCogABodOMtmwABAgLAGSBAgECjAgKg0Y23bAIECAgAZ4AAAQKNCgiARjfesgkQICAAnAECBAg0KiAAGt14yyZAgIAAcAYIECDQqIAAaHTjLZsAAQICwBkgQIBAowICoNGNt2wCBAgIAGeAAAECjQoIgEY33rIJECAgAJwBAgQINCogABrdeMsmQICAAHAGCBAg0KiAAGh04y2bAAECAsAZIECAQKMCAqDRjbdsAgQICABngAABAo0KCIBGN96yCRAgIACcAQIECDQqIAAa3XjLJkCAgABwBggQINCogABodOMtmwABAgLAGSBAgECjAgKg0Y23bAIECAgAZ4AAAQKNCgiARjfesgkQICAAnAECBAg0KiAAGt14yyZAgIAAcAYIECDQqIAAaHTjLZsAAQICwBkgQIBAowICoNGNv2TZF1988R7586PysWs+dtj495/J/34qH8duscUW5zZOZPkEVlZAAKzs1m5+Ybnx75SKt+Zj581UXpDPHZAQOLVRJssmsNICAmClt/fKF5eb/4H5zJuKS/9x6rZ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WrpqT7l/xuPdr8WWpvn5v0N3pc0wXNnVL/mcI1P8/Yv1eoU0KAwMgFBMCINyg35TenvUf2aLH7Xv+euUF/qMc1vy7NXFfL/1yUj6sUrt2hb8AUxlRCgMCCBQTAgsGr0+WG3L2Je/dm7n0ez82N+eg+F1y2NnN+If/dPd8w6/Gnmaf7cVQPAgQmLCAARrh5uRHvn7be3rO19+am/OCe11yuPPN2rytU+U3fozPXc9czl2sJEFi+gABY/h789k34LvmL7jV+frdHa92/3Hft86TvlY2dAHhm/v7FhXlPzVx7F+qUECAwYgEBMKLNyQ34D9POp/LR/eRP9XF+Cu84xPfkM/8DM9YHCxP/MPPdsFCnhACBEQsIgJFsTm6+3Q31k/m4ec+W7pmbcfcVw7of6WGbDHJecaDtMu93irXKCBAYoYAAGMGm5MZ77bTxiXz8cc92HpOb8Ot7XrPZ8vTynym4XmFM7w1QQFJCYMwCAmDJu7Pxxy9PTxuV9+W9bLfH5+bf/aTQoI/084EMuEdhUE8EF5CUEBizgABY4u7kZtv5vzcffZ9QfUdu/g+dR+vpqfsx0iMKY38gPexVqFNCgMBIBQTAEjcmN9vqO3FdtsuP5j/uX32Nn77LS0/75JpTCtd9Pz3cqFCnhACBkQoIgCVtTG60r83Uj+05/edSf/fceC/seV25PH11rzn0reIF26eX0vsIFMdTRoDAAgUEwAKxL5kqN9mX5899X1HznFzT/az/D+fdcvr7Qea4QW" <> ...}, ref: "7", join_ref: "4"} State: %{components: {%{}, %{}, 1}, join_ref: "4", serializer: Phoenix.Socket.V2.JSONSerializer, socket: #Phoenix.LiveView.Socket<id: "phx-FzRxEyuOZneo9-tE", endpoint: DigitsWeb.Endpoint, view: DigitsWeb.PageLive, parent_pid: nil, root_pid: #PID<0.2059.0>, router: DigitsWeb.Router, assigns: %{__changed__: %{}, flash: %{}, live_action: :index, prediction: nil}, transport_pid: #PID<0.2053.0>, ...>, topic: "lv:phx-FzRxEyuOZneo9-tE", upload_names: %{}, upload_pids: %{}}

Is this a known issue, or is just something wrong with my local version of the project? I did not change anything except updating the axon dependency because I got errors while compiling the dependencies.

Thanks for creating and publishing the project btw!

Thanks for any help.

Balczukiewicz commented 1 year ago

I have the same issue and I think it might be correlated with Evision.

EmilFattakhov commented 1 year ago

Faced the same problem and found the cause of the issue.

You have to modify a couple of calls inside model.ex, because calling Evision.imread/2 and Evision.resize no longer return a tuple.

mat = Evision.imread(path, flags: Evision.cv_IMREAD_GRAYSCALE())
mat = Evision.resize(mat, {28, 28})

You also have to modify Evision.Nx.to_nx/1 because it longer exists, to Evision.Mat.to_nx/1

Also, don't forget to cd into assets and run npm i draw-on-canvas in order to enable a canvas in a live_view

EmilFattakhov commented 1 year ago

For convenience, I cloned the repo and made necessary changes.

https://github.com/EmilFattakhov/handwritten_digits

philipbrown commented 1 year ago

Hey @EmilFattakhov Thanks for this. Feel free to send any PRs to this repo with updates 🙏