Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TensorFlow.jsで遊ぶ / nds59

TensorFlow.jsで遊ぶ / nds59

第59回 長岡IT開発者勉強会 (NDS#59) で発表した資料。
テーマ「学習・AI・入学」

kasacchiful

March 02, 2019
Tweet

More Decks by kasacchiful

Other Decks in Programming

Transcript

  1. 5FOTPS'MPXKTͰֶश // Define a model for linear regression. const model

    = tf.sequential(); model.add(tf.layers.dense({units: 1, inputShape: [1]})); // Prepare the model for training: Specify the loss and the optimizer. model.compile({loss: 'meanSquaredError', optimizer: 'sgd'}); // Generate some synthetic data for training. const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]); const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]); // Train the model using the data. model.fit(xs, ys).then(() => { // Use the model to do inference on a data point the model hasn't seen before: // Open the browser devtools to see the output model.predict(tf.tensor2d([5], [1, 1])).print(); }); Ҿ༻5SZ5FOTPS'MPXKT IUUQTDPEFQFOJPQFO FEJUBCMFUSVFFEJUPST
  2. શମਤ ਖ਼ղϥϕϧ෇ ֶशը૾σʔλ ֶश ਪ࿦ ະ஌ͷ ը૾σʔλ 7(( Ϟσϧ ൑ఆ

    ,FSBT ֶशࡁ Ϟσϧ 5FOTPS'MPXKT ܗࣜͷ ֶशࡁϞσϧ ί ϯ ό ʔ λ ม׵
  3. ,FSBTϞσϧͷίϯόʔτ // install $ pip install tensorflowjs // convert $

    tensorflowjs_converter --input_format keras model.h5 ./model // modelͷத਎ $ ls model/ group1-shard10of17 group1-shard13of17 group1-shard16of17 group1- shard2of17 group1-shard5of17 group1-shard8of17 group1-shard11of17 group1-shard14of17 group1-shard17of17 group1- shard3of17 group1-shard6of17 group1-shard9of17 group1-shard12of17 group1-shard15of17 group1-shard1of17 group1- shard4of17 group1-shard7of17 model.json IܗࣜͷϞσϧϑΝΠϧΛίϯόʔτ͠ɺUBSHFU@EJS ͜͜Ͱ͸NPEFM ʹอଘ
  4. ,FSBTϞσϧͷίϯόʔτ import keras import tensorflowjs as tfjs model = keras.models.load_model(”./model.h5”)

    tfjs.converters.save_keras_model(model, ’./model’) 1ZUIPOεΫϦϓτ্Ͱ΋ɺ,FSBTϞσϧϑΝΠϧอଘ࣌ʹม׵Մೳ
  5. 1PTF/FUͰݕग़Ͱ͖Δ෦Ґ w ඓ w ࠨ؟ɺӈ؟ w ࠨࣖɺӈࣖ w ࠨݞɺӈݞ w

    ࠨͻ͡ɺӈͻ͡ w ࠨखटɺӈखट w ࠨ৲ɺӈ৲ w ࠨͻ͟ɺӈͻ͟ w ࠨ଍टɺӈ଍ट