Es ist meine Schuld, ich habe genau diesen Code, ich will nicht alle nutzlos Code einzufügen zu tun, dass
"""Import."""
import tensorflow as tf
import cv2
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, shape=[512, 512])
y_ = tf.placeholder(tf.float32, shape=[1, 1])
def get_image_from_file(file_name):
"""Function get_image_from_file."""
return cv2.resize(cv2.imread(file_name, 0), (512, 512),
interpolation=cv2.INTER_CUBIC)
def weight_variable(shape):
"""Foo."""
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
"""Foo."""
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
def conv2d(x, w):
"""Foo."""
return tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='SAME')
def max_pool_2x2(x):
"""Max pool 2x2."""
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1], padding='SAME')
if __name__ == "__main__":
# 1st layer
w_conv1 = weight_variable([5, 5, 1, 16])
b_conv1 = bias_variable([16])
x_image = tf.reshape(x, [-1, 512, 512, 1])
h_conv1 = tf.nn.relu(conv2d(x_image, w_conv1) + b_conv1)
h_pool1 = max_pool_2x2(h_conv1)
# 2nd layer
w_conv2 = weight_variable([5, 5, 16, 32])
b_conv2 = bias_variable([32])
h_conv2 = tf.nn.relu(conv2d(h_pool1, w_conv2) + b_conv2)
h_pool2 = max_pool_2x2(h_conv2)
# connection layer
w_fc1 = weight_variable([32 * 32 * 64, 128])
b_fc1 = bias_variable([128])
h_pool2_flat = tf.reshape(h_pool2, [-1, 32 * 32 * 64])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, w_fc1) + b_fc1)
# zapobieganie przeuczeniu
keep_prob = tf.placeholder(tf.float32)
h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)
# output layer
w_fc2 = weight_variable([128, 1])
b_fc2 = bias_variable([1])
y_conv = tf.nn.softmax(tf.matmul(h_fc1_drop, w_fc2) + b_fc2)
cross_entropy = -tf.reduce_sum(y_ * tf.log(y_conv))
train_step = tf.train.AdamOptimizer(1e-4).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))
sess.run(tf.initialize_all_variables())
for i in range(24):
img = get_image_from_file("./MOJE/koty_nauka/kot" + str(i + 1) +
".jpg")
out = y_conv.eval(feed_dict={
x: img, y_: [[1]], keep_prob: 1.0})
print("----")
print(out)
Wie trainieren Sie Ihr Netzwerk? Welchen Datensatz verwenden Sie für das Training? – keveman
Wo ist Ihr Optimierer, Sitzung oder Ihre "y_conv". Veröffentlichen Sie relevante Teile des Codes, wenn Sie nach Antworten suchen! – shekkizh
Wäre das nicht besser als Klassifizierungsproblem und nicht als Regressionsproblem geeignet? – ode2k