Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

NxでMNISTの手書き数字画像分類を試す / Training MNIST Datasets...

NxでMNISTの手書き数字画像分類を試す / Training MNIST Datasets with Nx

NervesJP #15 Nxを触ってみる回
https://nerves-jp.connpass.com/event/205125/

Kentaro Kuribayashi

February 25, 2021
Tweet

More Decks by Kentaro Kuribayashi

Other Decks in Technology

Transcript

  1. ͜Μͳײ͡ͰKeras෩ʹࢼͤ·͢ ./*45σʔλͷಡΈࠐΈ [x_train, y_train, x_test, y_test] = Jnnnx.MNIST.Dataset.load_data() σʔλͷ੔ܗͱਖ਼نԽ x_train

    = x_train |> Nx.reshape({60000, 28*28}, names: [:batch, :input]) |> Nx.divide(255) x_test = x_test |> Nx.reshape({10000, 28*28}, names: [:batch, :input]) |> Nx.divide(255) POFIPUFODPEJOH y_train = y_train |> Jnnnx.Utils.to_categorical(10, names: [:batch, :output]) y_test = y_test |> Jnnnx.Utils.to_categorical(10, names: [:batch, :output]) τϨʔχϯάσʔλΛ༻ֶ͍ͯश params = Jnnnx.fit(x_train, y_train, epoch: 5, batch_size: 50, learning_rate: 0.01) ςετσʔλΛ༻͍ͯධՁ score = Jnnnx.evaluate(params, x_test, y_test) IO.puts("Accuracy: #{Nx.to_scalar(score)}")
  2. ˔ +PTÉͷϥΠϒίʔσΟϯάಈըΛ؍ͳ͕Βࣸܦͨ͠ ˔ ػցֶशϥΠϒϥϦͷΑ͏ʹ࢖͑ΔΑ͏ʹ੔ཧͨ͠ ˓ ࣸܦͨ͠ίʔυΛϥΠϒϥϦͬΆ͍ϑΝΠϧߏ଄Ͱ഑ஔ ˓ ϋΠύʔύϥϝλΛؔ਺ͷҾ਺ͱͯ͠౉ͤΔΑ͏ʹͨ͠ ˔ ./*45ͷσʔληοτΛऔಘ͢ΔϞδϡʔϧΛ௥Ճͨ͠

    ˔ ֶशͨ͠ϞσϧΛɺςετσʔλʹΑͬͯධՁ͢Δؔ਺Λ௥Ճͨ͠ ˠಈըͰσϞͯͨ͠ίʔυͷݩʹͳ͍ͬͯΔ΋ͷͱࢥΘΕΔ΋ͷ͕ FYMBͷ΄͏ͷFYBNQMFTʹ͋ͬͨʂ˞ ΍ͬͨ͜ͱ ˞IUUQTHJUIVCDPNFMJYJSOYOYCMPCNBJOFYMBFYBNQMFTNOJTUFYT