I want to receive a 5*5 array in Tensorflow, learn and print out the 1*5 answer.

Asked 2 years ago, Updated 2 years ago, 79 views

Machine learning is a mechanism for finding the laws, characteristics, and patterns of input data. In the case of machine learning with teachers, what are the intentions (law, feature, pattern) of teacher data?

For example,

1000
0 1 0 0 0
0 1 0 0 0  →  0 1 0 0 0
0 0 1 0 0
0 0 0 0 1
 input data answer data

1 0 0 0 0
0 0 1 0 0
0 0 1 0 0  →  0 0 0 1 0
0 0 0 1 0
0 0 0 0 1
 input data answer data

If was the training data, the input data would be

1000
0 1 0 0 0
0 0 1 0 0 
0 0 0 0 1
0 0 0 0 1

I'd like to learn and find out what the answer is.

In mahjong, you have to throw away one of the 14 tiles you used to imitate yourself.
There are no perfect laws, but there are some.
(Sorry for the difficulty in explaining in Japanese.)

import input_data
mnist=input_data.read_data_sets('MNIST_data', one_hot=True)

import tensorflow as tf
sess=tf.InteractiveSession()

x = tf.placeholder (tf.float32,shape=[None,25])
y_=tf.placeholder(tf.float32,shape=[None,5])

W = tf.Variable(tf.zeros([25,5]))
b=tf.Variable(tf.zeros([5]))

sess.run(tf.initialize_all_variables())

y = tf.nn.softmax(tf.matmul(x,W)+b)

def weight_variable(shape):
  initial=tf.truncated_normal(shape, stddev=0.1)
  return tf.Variable (initial)

def bias_variable(shape):
  initial=tf.constant(0.1,shape=shape)
  return tf.Variable (initial)

def conv2d(x,W):
  return tf.nn.conv2d(x,W,strides=[1,1,1,1],padding='SAME')

def max_pool_2x2(x):
  return tf.nn.max_pool(x,ksize=[1,2,2,1],
                         strides=[1,2,2,1], padding='SAME')

W_conv1 = weight_variable ([5,5,1,32])
b_conv1 = bias_variable([32])

x_image=tf.reshape(x,[-1,5,5,1])

h_conv1 = tf.nn.relu(conv2d(x_image,W_conv1) + b_conv1)
h_pool1 = max_pool_2x2(h_conv1)

W_conv2 = weight_variable ([5, 5, 32, 64])
b_conv2 = bias_variable ([64])

h_conv2 = tf.nn.relu(conv2d(h_conv1, W_conv2) + b_conv2)
h_pool2 = max_pool_2x2(h_conv2)

W_fc1 = weight_variable ([5*5*64,512])
b_fc1 = bias_variable ([512])

h_pool2_flat=tf.reshape(h_conv2, [-1,5*5*64])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)

keep_prob=tf.placeholder(tf.float32)
h_fc1_drop=tf.nn.dropout(h_fc1, keep_prob)

W_fc2 = weight_variable ([512,5])
b_fc2 = bias_variable([5])

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))
acuracy=tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
sess.run(tf.initialize_all_variables())

for i in range (10000):
  batch=mnist.train.next_batch(500)
  if i%100 == 0:
    train_accuracy=accuracy.eval(feed_dict={
        x:batch[0], y_:batch[1], keep_prob:1.0})
    print("step%d, training acuity%g"%(i,train_accuracy))
  train_step.run (feed_dict={x:batch[0], y_:batch[1], keep_prob:0.5})

print("test acuity%g"%accuracy.eval(feed_dict={
    x:mnist.test.images, y_:mnist.test.labels, keep_prob:1.0}))

python tensorflow

2022-09-30 21:21

1 Answers

I understand that (5, 5) is a sample, and what I really want to do is to have 14 mahjong tiles x 34 kinds.

First of all, what's wrong with the code you presented?
Will there be an error?Is the training progressing?

Also, it seems that there is no connection between the learning data and the answer for the sample example.
If you set it to (5, 5), for example, if you play poker with a card with no suit and only 1-5 numbers, you can throw it away. For example,
[1, 2, 2, 3, 5] If you have it, throw away 2 is the correct answer
[1,3,3,4,5] If you have it, discarding 4 is the correct answer
it seemed to me that there was no law.(Is the former aimed at straightening and the latter aimed at three cards?)If there is such a complexity, I think a considerable amount of learning data will be needed.)
However, I can only ask you to review whether the learning data is really correct or not because there is no conflict in discussing this point here.
If the MNIST code remains the same and the learning data is appropriate (though MNIST's network is not the best solution to this problem), you should do some learning.

Also, the problem you really want to set up is
I will choose the appropriate one (14,34) out of 14 inputs that can be 34 types, but
If so, the input should be 14*34 as flattened (476) (if you follow MNIST).
((34) should also be divided into (4,9) sensors of Manko, Tsutsuko, Cable, and Characters, but the missing parts of the wind and Samwon tiles are not used

Also, the answer data should be a sensor the size of (34) or (14).
(34) 34Which tiles of 34 types were made?
(14) 手持ちWhich of the 14 tiles you have in your hand have been removed

Tensorflow is a platform that designs neural networks by itself, but
You don't seem to understand the network design itself.
Why don't you study networking instead of coding first?


2022-09-30 21:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.