{"action":"opened","issue":{"url":"https://api.github.com/repos/tiny-dnn/tiny-dnn/issues/964","repository_url":"https://api.github.com/repos/tiny-dnn/tiny-dnn","labels_url":"https://api.github.com/repos/tiny-dnn/tiny-dnn/issues/964/labels{/name}","comments_url":"https://api.github.com/repos/tiny-dnn/tiny-dnn/issues/964/comments","events_url":"https://api.github.com/repos/tiny-dnn/tiny-dnn/issues/964/events","html_url":"https://github.com/tiny-dnn/tiny-dnn/issues/964","id":331236623,"node_id":"MDU6SXNzdWUzMzEyMzY2MjM=","number":964,"title":"How to implement a Tensorflow model in tiny-dnn?","user":{"login":"FohlenAFK","id":28490587,"node_id":"MDQ6VXNlcjI4NDkwNTg3","avatar_url":"https://avatars1.githubusercontent.com/u/28490587?v=4","gravatar_id":"","url":"https://api.github.com/users/FohlenAFK","html_url":"https://github.com/FohlenAFK","followers_url":"https://api.github.com/users/FohlenAFK/followers","following_url":"https://api.github.com/users/FohlenAFK/following{/other_user}","gists_url":"https://api.github.com/users/FohlenAFK/gists{/gist_id}","starred_url":"https://api.github.com/users/FohlenAFK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FohlenAFK/subscriptions","organizations_url":"https://api.github.com/users/FohlenAFK/orgs","repos_url":"https://api.github.com/users/FohlenAFK/repos","events_url":"https://api.github.com/users/FohlenAFK/events{/privacy}","received_events_url":"https://api.github.com/users/FohlenAFK/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-11T15:24:06Z","updated_at":"2018-06-11T15:24:06Z","closed_at":null,"author_association":"NONE","body":"Hi guy's,\r\nI have written a simpel network with tensorflow in python and try to get the same result with tiny-dnn in c++ but I'm having trouble implementing the model correctly\r\n\r\n  // featrue = 0-4, label = 5\r\n  // Example Data: 23.18, 27.272, 426, 721.25, 0.00479, 1\r\n\r\n```\r\n#!/usr/bin/env python\r\n\r\nimport tensorflow as tf\r\nimport numpy as np\r\nimport input_data\r\n\r\ndef init_weights(shape, dev):\r\n    return tf.Variable(tf.random_normal(shape, stddev=dev))\r\n\r\ndef model(X, w_h, w_o):\r\n    h = tf.nn.sigmoid(tf.matmul(X, w_h)) # this is a basic mlp, think 2 stacked logistic regressions\r\n    return tf.matmul(h, w_o) # note that we dont take the softmax at the end because our cost fn does that for us\r\n\r\ndata = input_data.read_data_sets(\"datasets/\");\r\ntrX, trY = data.train.features, data.train.labels;\r\ntvX, tvY = data.validate.features, data.validate.labels;\r\nteX, teY = data.test.features, data.test.labels;\r\n\r\nX = tf.placeholder(\"float32\", [None, 5]) # features\r\nY = tf.placeholder(\"float32\", [None, 1]) # labels\r\n\r\nw_h = init_weights([5, 100], np.sqrt(2 / np.prod(X.get_shape().as_list()[1:]))) # create symbolic variables\r\nw_o = init_weights([100, 1], np.sqrt(2 / np.prod(Y.get_shape().as_list()[1:])))\r\n\r\npy_x = model(X, w_h, w_o)\r\n\r\ncost = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=py_x,labels=Y)) # compute costs\r\ntrain_op = tf.train.GradientDescentOptimizer(0.05).minimize(cost) # construct an optimizer\r\npredict_op = tf.nn.sigmoid(py_x);\r\n\r\ncost_history = [];\r\naccuracy_history = [];\r\n\r\n# Launch the graph in a session\r\nwith tf.Session() as sess:\r\n    # you need to initialize all variables\r\n    tf.initialize_all_variables().run()\r\n\r\n    for i in range(300):\r\n        for start, end in zip(range(0, len(trX), 128), range(128, len(trX)+1, 128)):\r\n            sess.run(train_op, feed_dict={X: trX[start:end], Y: trY[start:end]});\r\n\r\n        cost_history.append(sess.run(cost, feed_dict={X: tvX, Y:tvY}));\r\n        print(i, 'cost:', sess.run(cost, feed_dict={X: tvX, Y:tvY}));\r\n        print(i, 'accuracy:', (np.round(sess.run(predict_op, feed_dict={X: tvX})) == tvY).mean())\r\n\r\n\r\n    print('Final score:', (np.round(sess.run(predict_op, feed_dict={X: teX})) == teY).mean())\r\n```\r\nFinal score: 97,5%\r\n\r\n```\r\nint main(int argc, char **argv) {\r\n  DataSet trainDataSet = loadData(\"datasets/data_training.csv\");\r\n  DataSet testDataSet = loadData(\"datasets/data_test.csv\");\r\n  \r\n  network<sequential> nn;\r\n  nn << fully_connected_layer(5, 100) << sigmoid_layer()  // features\r\n     << fully_connected_layer(100, 1) << sigmoid_layer(); // labelse \r\n\r\n  size_t batch_size = 1;\r\n  size_t epochs = 300;\r\n  gradient_descent optimizer;\r\n  timer t;\r\n  nn.fit<mse>(optimizer, trainDataSet.vInputData, trainDataSet.vOutputData, batch_size, epochs,\r\n              [&](){\r\n                t.elapsed();\r\n                t.reset();\r\n              },\r\n              [&]() {\r\n                result res = nn.test(testDataSet.vInputData,\r\n                                     testDataSet.vOutputDataLabel);\r\n                cout << res.num_success << \"/\" << res.num_total << endl;\r\n              });\r\n\r\n  double loss =\r\n      nn.get_loss<mse>(trainDataSet.vInputData, trainDataSet.vOutputData);\r\n  cout << \"mse : \" << loss << endl;\r\n\r\n  return 0;\r\n}\r\n```\r\n\r\nResult for each epoch: still 78,9889253%"}}
{"actor":{"display_login":"FohlenAFK"}}