@ -0,0 +1,2 @@
|
||||
model_checkpoint_path: "area"
|
||||
all_model_checkpoint_paths: "area"
|
@ -0,0 +1,96 @@
|
||||
import tensorflow as tf
|
||||
from process_data import DataProcessor
|
||||
|
||||
batch_size = 128
|
||||
learning_rate = 1e-4
|
||||
aspect = 'province'
|
||||
data_processor = DataProcessor(aspect)
|
||||
dir = './'
|
||||
model_name = aspect
|
||||
|
||||
input_x = tf.placeholder(dtype=tf.float32, shape=[None, 20, 20], name='input_x')
|
||||
input_y = tf.placeholder(dtype=tf.float32, shape=[None, 34], name='input_y')
|
||||
|
||||
with tf.name_scope('conv1'):
|
||||
W_C1 = tf.Variable(tf.truncated_normal(shape=[3, 3, 1, 32], stddev=0.1))
|
||||
b_C1 = tf.Variable(tf.constant(0.1, tf.float32, shape=[32]))
|
||||
X = tf.reshape(input_x, [-1, 20, 20, 1])
|
||||
featureMap_C1 = tf.nn.relu(tf.nn.conv2d(X, W_C1, strides=[1, 1, 1, 1], padding='SAME') + b_C1)
|
||||
|
||||
with tf.name_scope('conv2'):
|
||||
W_C2 = tf.Variable(tf.truncated_normal(shape=[3, 3, 32, 64], stddev=0.1))
|
||||
b_C2 = tf.Variable(tf.constant(0.1, tf.float32, shape=[64]))
|
||||
featureMap_C2 = tf.nn.relu(tf.nn.conv2d(featureMap_C1, W_C2, strides=[1, 1, 1, 1], padding='SAME') + b_C2)
|
||||
|
||||
with tf.name_scope('pooling2'):
|
||||
featureMap_S2 = tf.nn.max_pool(featureMap_C2, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID')
|
||||
|
||||
with tf.name_scope('conv3'):
|
||||
W_C3 = tf.Variable(tf.truncated_normal(shape=[3, 3, 64, 8], stddev=0.1))
|
||||
b_C3 = tf.Variable(tf.constant(0.1, shape=[8], dtype=tf.float32))
|
||||
featureMap_C3 = tf.nn.relu(tf.nn.conv2d(featureMap_S2, filter=W_C3, strides=[1, 1, 1, 1], padding='SAME') + b_C3)
|
||||
|
||||
with tf.name_scope('pooling3'):
|
||||
featureMap_S3 = tf.nn.max_pool(featureMap_C3, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID')
|
||||
|
||||
with tf.name_scope('fulnet'):
|
||||
featureMap_flatten = tf.reshape(featureMap_S3, [-1, 5*5*8])
|
||||
W_F4 = tf.Variable(tf.truncated_normal(shape=[5*5*8, 512], stddev=0.1))
|
||||
b_F4 = tf.Variable(tf.constant(0.1, shape=[512], dtype=tf.float32))
|
||||
out_F4 = tf.nn.relu(tf.matmul(featureMap_flatten, W_F4) + b_F4)
|
||||
out_F4 = tf.nn.dropout(out_F4, keep_prob=0.5)
|
||||
|
||||
with tf.name_scope('output'):
|
||||
W_OUTPUT = tf.Variable(tf.truncated_normal(shape=[512, 34], stddev=0.1))
|
||||
b_OUTPUT = tf.Variable(tf.constant(0.1, shape=[34], dtype=tf.float32))
|
||||
logits = tf.matmul(out_F4, W_OUTPUT)+b_OUTPUT
|
||||
|
||||
loss = tf.reduce_sum(tf.nn.softmax_cross_entropy_with_logits(labels=input_y, logits=logits))
|
||||
train_op = tf.train.AdamOptimizer(learning_rate).minimize(loss)
|
||||
predictY = tf.nn.softmax(logits)
|
||||
y_pred = tf.arg_max(predictY, 1)
|
||||
bool_pred = tf.equal(tf.arg_max(input_y, 1), y_pred)
|
||||
right_rate = tf.reduce_mean(tf.to_float(bool_pred))
|
||||
|
||||
saver = tf.train.Saver()
|
||||
|
||||
|
||||
def load_model(sess, dir, model_name):
|
||||
ckpt = tf.train.get_checkpoint_state(dir)
|
||||
if ckpt and ckpt.model_checkpoint_path:
|
||||
print('*'*30)
|
||||
print('load latest model......')
|
||||
saver.restore(sess, dir+'.\\'+model_name)
|
||||
print('*'*30)
|
||||
|
||||
|
||||
def save_model(sess, dir, model_name):
|
||||
saver.save(sess, dir+model_name)
|
||||
|
||||
|
||||
with tf.Session() as sess:
|
||||
sess.run(tf.initialize_all_variables())
|
||||
step = 1
|
||||
display_interval = 200
|
||||
max_epoch = 500
|
||||
epoch = 1
|
||||
acc = 0
|
||||
load_model(sess, dir=dir, model_name=model_name)
|
||||
while True:
|
||||
if step % display_interval == 0:
|
||||
image_batch, label_batch, epoch = data_processor.next_valid_batch(batch_size)
|
||||
acc = sess.run(right_rate, feed_dict={input_x: image_batch, input_y: label_batch})
|
||||
print({str(epoch)+':'+str(step): acc})
|
||||
image_batch, label_batch, epoch = data_processor.next_train_batch(batch_size)
|
||||
sess.run([loss, train_op], {input_x: image_batch, input_y: label_batch})
|
||||
if epoch > max_epoch:
|
||||
break
|
||||
step += 1
|
||||
while True:
|
||||
test_img, test_lab, test_epoch = data_processor.next_test_batch(batch_size)
|
||||
test_acc = sess.run(right_rate, {input_x: test_img, input_y: test_lab})
|
||||
acc = test_acc * 0.8 + acc * 0.2
|
||||
if test_epoch != epoch:
|
||||
print({'Test Over..... acc:': acc})
|
||||
break
|
||||
save_model(sess, dir, model_name)
|
@ -0,0 +1,102 @@
|
||||
maps={
|
||||
"province":
|
||||
{
|
||||
"0":"皖",
|
||||
"1":"沪",
|
||||
"2":"津",
|
||||
"3":"渝",
|
||||
"4":"冀",
|
||||
"5":"晋",
|
||||
"6":"蒙",
|
||||
"7":"辽",
|
||||
"8":"吉",
|
||||
"9":"黑",
|
||||
"10":"苏",
|
||||
"11":"浙",
|
||||
"12":"京",
|
||||
"13":"闽",
|
||||
"14":"赣",
|
||||
"15":"鲁",
|
||||
"16":"豫",
|
||||
"17":"鄂",
|
||||
"18":"湘",
|
||||
"19":"粤",
|
||||
"20":"桂",
|
||||
"21":"琼",
|
||||
"22":"川",
|
||||
"23":"贵",
|
||||
"24":"云",
|
||||
"25":"藏",
|
||||
"26":"陕",
|
||||
"27":"甘",
|
||||
"28":"青",
|
||||
"29":"宁",
|
||||
"30":"新"
|
||||
},
|
||||
"area":
|
||||
{
|
||||
"0":"A",
|
||||
"1":"B",
|
||||
"2":"C",
|
||||
"3":"D",
|
||||
"4":"E",
|
||||
"5":"F",
|
||||
"6":"G",
|
||||
"7":"H",
|
||||
"8":"I",
|
||||
"9":"J",
|
||||
"10":"K",
|
||||
"11":"L",
|
||||
"12":"M",
|
||||
"13":"N",
|
||||
"14":"O",
|
||||
"15":"P",
|
||||
"16":"Q",
|
||||
"17":"R",
|
||||
"18":"S",
|
||||
"19":"T",
|
||||
"20":"U",
|
||||
"21":"V",
|
||||
"22":"W",
|
||||
"23":"X",
|
||||
"24":"Y",
|
||||
"25":"Z"
|
||||
},
|
||||
"letter":
|
||||
{
|
||||
"0":"0",
|
||||
"1":"1",
|
||||
"2":"2",
|
||||
"3":"3",
|
||||
"4":"4",
|
||||
"5":"5",
|
||||
"6":"6",
|
||||
"7":"7",
|
||||
"8":"8",
|
||||
"9":"9",
|
||||
"10":"A",
|
||||
"11":"B",
|
||||
"12":"C",
|
||||
"13":"D",
|
||||
"14":"E",
|
||||
"15":"F",
|
||||
"16":"G",
|
||||
"17":"H",
|
||||
"18":"J",
|
||||
"19":"K",
|
||||
"20":"L",
|
||||
"21":"M",
|
||||
"22":"N",
|
||||
"23":"P",
|
||||
"24":"Q",
|
||||
"25":"R",
|
||||
"26":"S",
|
||||
"27":"T",
|
||||
"28":"U",
|
||||
"29":"V",
|
||||
"30":"W",
|
||||
"31":"X",
|
||||
"32":"Y",
|
||||
"33":"Z"
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 665 B |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 703 B |
After Width: | Height: | Size: 708 B |
After Width: | Height: | Size: 727 B |
After Width: | Height: | Size: 646 B |
After Width: | Height: | Size: 683 B |
After Width: | Height: | Size: 702 B |
After Width: | Height: | Size: 684 B |
After Width: | Height: | Size: 692 B |
After Width: | Height: | Size: 675 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 645 B |
After Width: | Height: | Size: 685 B |
After Width: | Height: | Size: 678 B |
After Width: | Height: | Size: 684 B |
After Width: | Height: | Size: 695 B |
After Width: | Height: | Size: 695 B |
After Width: | Height: | Size: 661 B |
After Width: | Height: | Size: 657 B |
After Width: | Height: | Size: 693 B |
After Width: | Height: | Size: 708 B |
After Width: | Height: | Size: 629 B |
After Width: | Height: | Size: 685 B |
After Width: | Height: | Size: 698 B |
After Width: | Height: | Size: 623 B |
After Width: | Height: | Size: 681 B |
After Width: | Height: | Size: 776 B |
After Width: | Height: | Size: 728 B |
After Width: | Height: | Size: 716 B |
After Width: | Height: | Size: 688 B |
After Width: | Height: | Size: 690 B |
After Width: | Height: | Size: 638 B |
After Width: | Height: | Size: 675 B |
After Width: | Height: | Size: 675 B |
After Width: | Height: | Size: 693 B |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 689 B |
After Width: | Height: | Size: 700 B |
After Width: | Height: | Size: 728 B |
After Width: | Height: | Size: 680 B |
After Width: | Height: | Size: 683 B |
After Width: | Height: | Size: 688 B |
After Width: | Height: | Size: 681 B |
After Width: | Height: | Size: 701 B |
After Width: | Height: | Size: 656 B |
After Width: | Height: | Size: 684 B |
After Width: | Height: | Size: 712 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 647 B |
After Width: | Height: | Size: 779 B |
After Width: | Height: | Size: 692 B |
After Width: | Height: | Size: 668 B |
After Width: | Height: | Size: 696 B |
After Width: | Height: | Size: 691 B |
After Width: | Height: | Size: 728 B |
After Width: | Height: | Size: 837 B |