Speichern oder exportieren Sie die GEWICHTE und biases in TensorFlow für nicht-Python-Replikation

Habe ich gebaut, ein neuronales Netzwerk, das führt Recht gut, und ich möchte replizieren mein Modell in einem nicht-Python-Umgebung. Richte ich mein Netzwerk wie folgt:

sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, shape=[None, 23])
y_ = tf.placeholder(tf.float32, shape=[None, 2])
W = tf.Variable(tf.zeros([23,2]))
b = tf.Variable(tf.zeros([2]))
sess.run(tf.initialize_all_variables())
y = tf.nn.softmax(tf.matmul(x,W) + b)

Wie bekomme ich eine zu entziffern .csv-oder .txt meine GEWICHTE und Neigungen?

EDIT: Unten ist meine vollständige Skript:

import csv
import numpy
import tensorflow as tf

data = list(csv.reader(open("/Users/sjayaram/developer/TestApp/out/production/TestApp/data.csv")))
[[float(j) for j in i] for i in data]
numpy.random.shuffle(data)
results=data

#delete results from data
data = numpy.delete(data, [23, 24], 1)
#delete data from results
results = numpy.delete(results, range(23), 1)

sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, shape=[None, 23])
y_ = tf.placeholder(tf.float32, shape=[None, 2])
W = tf.Variable(tf.zeros([23,2]))
b = tf.Variable(tf.zeros([2]))
sess.run(tf.initialize_all_variables())
y = tf.nn.softmax(tf.matmul(x,W) + b)
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

#train the model, saving 80 entries for testing
#batch-size: 40
for i in range(0, 3680, 40):
  train_step.run(feed_dict={x: data[i:i+40], y_: results[i:i+40]})

correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(accuracy.eval(feed_dict={x: data[3680:], y_: results[3680:]}))
InformationsquelleAutor surf-n-cherf | 2016-08-01
Schreibe einen Kommentar