kasacchiful
March 02, 2019
160

# TensorFlow.jsで遊ぶ / nds59

テーマ「学習・AI・入学」

March 02, 2019

## Transcript

2. ### ࣗݾ঺հ w ּݪ޺ !LBTBDDIJGVM  w ৽ׁࢢࡏॅ w 3VCZ͕͓ؾʹೖΓ w

+B445৽ׁ࣮ߦҕһ w +"846(৽ׁࢧ෦

6. ### 5FOTPS'MPXKTͱ͸ʁ w 5FOTPS'MPXͷ+BWB4DSJQU൛ w 8FCϒϥ΢β΍/PEFKTͰಈ࡞Մೳ w 5FOTPS'MPX΍,FSBTͷֶशࡁϞσϧΛίϯόʔτՄೳ w 5FOTPS'MPXKT୯ମͰ΋ֶशՄೳ w

8FC(-͕༗ޮͳΒɺ(16΋࢖͑Δ
7. ### 5FOTPS'MPXKTͰֶश // 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(); }); Ҿ༻5SZ5FOTPS'MPXKT IUUQTDPEFQFOJPQFO FEJUBCMFUSVFFEJUPST

11. ### ֶश͢Δը૾ w ৽ׁΛ୅ද͢Δ#ڃάϧϝ w ࡫ஂࢠ w ֟ͷछʢُా੡՛ʗӽޙ੡՛ʗ࿘Ֆ԰੡՛ͳͲʣ w ΠλϦΞϯʢΈ͔͖ͮͱϑϨϯυ͸෼͚͍ͯ·ͤΜʣ w

όεηϯλʔͷΧϨʔʢ෱ਆ௮͚ଟΊͷԫ৭͍ΧϨʔͰ ͢ʣ
12. ### શମਤ ਖ਼ղϥϕϧ෇ ֶशը૾σʔλ ֶश ਪ࿦ ະ஌ͷ ը૾σʔλ 7(( Ϟσϧ ൑ఆ

,FSBT ֶशࡁ Ϟσϧ 5FOTPS'MPXKT ܗࣜͷ ֶशࡁϞσϧ ί ϯ ό ʔ λ ม׵
13. ### ,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 ʹอଘ
14. ### ,FSBTϞσϧͷίϯόʔτ import keras import tensorflowjs as tfjs model = keras.models.load_model(”./model.h5”)

tfjs.converters.save_keras_model(model, ’./model’) 1ZUIPOεΫϦϓτ্Ͱ΋ɺ,FSBTϞσϧϑΝΠϧอଘ࣌ʹม׵Մೳ

19. ### 1PTF/FUͰݕग़Ͱ͖Δ෦Ґ w ඓ w ࠨ؟ɺӈ؟ w ࠨࣖɺӈࣖ w ࠨݞɺӈݞ w

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