Ich versuche einfaches neuronales Netzwerk zu trainieren, die besteht aus:Neuronales Netz Blind erraten
- Convolution Schichtfilter (5x5) 8 x, schreiten 2.
- Max Pooling 25x25 (das Bild ist ein bisschen geringe Menge an Details)
- Planschleifen Ausgabe in (2x2x8) Vektor
- Classifier mit logistischer Regression
Altogethe r Netzwerk hat < 1000 Gewichte.
Datei: nn.py
#!/bin/python
import tensorflow as tf
import create_batch
# Prepare data
batch = create_batch.batch
x = tf.reshape(batch[0], [-1,100,100,3])
y_ = batch[1]
# CONVOLUTION NETWORK
# For initialization
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.3)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.2, shape=shape)
return tf.Variable(initial)
# Convolution with stride 1
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1, 2, 2, 1], padding='SAME')
def max_pool_25x25(x):
return tf.nn.max_pool(x, ksize=[1, 25, 25, 1],
strides=[1, 25, 25, 1], padding='SAME')
# First layer
W_conv1 = weight_variable([5, 5, 3, 8])
b_conv1 = bias_variable([8])
x_image = tf.reshape(x, [-1,100,100,3])
# First conv1
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
h_pool1 = max_pool_25x25(h_conv1)
# Dense connection layer
# make data flat
W_fc1 = weight_variable([2 * 2 * 8, 2])
b_fc1 = bias_variable([2])
h_pool1_flat = tf.reshape(h_pool1, [-1, 2*2*8])
y_conv = tf.nn.softmax(tf.matmul(h_pool1_flat, W_fc1) + b_fc1)
#Learning
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_conv), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.001).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
# Session
sess = tf.Session()
sess.run(tf.initialize_all_variables())
# Start input enqueue threads.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
for i in range(200):
if i%10 == 0:
train_accuracy = accuracy.eval(session=sess)
print("step %d, training accuracy %g"%(i, train_accuracy))
train_step.run(session=sess)
Datei: create_batch.py
#!/bin/python
import tensorflow as tf
PATH1 = "../dane/trening/NK/"
PATH2 = "../dane/trening/K/"
def create_labeled_image_list():
filenames = [(PATH1 + "nk_%d.png" % i) for i in range(300)]
labels = [[1,0] for i in range(300)]
filenames += [(PATH2 + "kulki_%d.png" % i) for i in range(300)]
labels += [[0,1] for i in range(300)]
return filenames, labels
def read_images_from_disk(input_queue):
label = input_queue[1]
file_contents = tf.read_file(input_queue[0])
example = tf.image.decode_png(file_contents, channels=3)
example.set_shape([100, 100, 3])
example = tf.to_float(example)
print ("READ, label:")
print(label)
return example, label
# Start
image_list, label_list = create_labeled_image_list()
# Create appropriate tensors for naming
images = tf.convert_to_tensor(image_list, dtype=tf.string)
labels = tf.convert_to_tensor(label_list, dtype=tf.float32)
input_queue = tf.train.slice_input_producer([images, labels],
shuffle=True)
image, label = read_images_from_disk(input_queue)
batch = tf.train.batch([image, label], batch_size=600)
Ich Fütterung 100x100 Bilder Ich habe zwei jeweiligen Kategorie 300 Bilder je. Grundsätzlich zufällig initialisiert Netzwerk in Schritt 0 hat eine bessere Genauigkeit als trainiert. Netzwerk hört auf zu lernen, nachdem es 0,5 Genauigkeit erreicht hat (im Grunde Münzwurf). Bilder enthalten blaues blooby Ding (Klasse 1) oder Gras (Klasse 2).
Ich bin Netzwerkbildung mit ganzen Bildset auf einmal (600 Bilder), die Verlustfunktion ist Cross-Entropie.
Was mache ich falsch?
Könnten Sie bitte den ganzen Code posten? Mit dem Code auf, wie Sie die Trainingssitzung etc. ausführen. Auch Gewichtvariablen werden auf eine ungerade Art initialisiert (sie sind nicht tf.Variable). Ehrlich gesagt würde ich vorschlagen, dass Sie meinen Code hier überprüfen, ich erstelle dort Convnets und trainiere sie: https://github.com/MaxKHK/Udacity_DeepLearningAssignments/blob/master/Assignment4/4_convolutions.ipynb –
@MaximHaytovich ganze Code-Beiträge werden nie auf ermutigt stapeln und löscht tatsächlich die Buchungsbedingungen. – rogue39nin
@david ich meinte 'Post auf Pastebin und Link hier hinzufügen' oder smth mag es - ursprüngliche Frage hatte wirklich zu wenig Informationen, um mit –