import tensorflow as tf
# from helpFunctions import *
from models import *
import cv2
import os
import numpy as np
import models
import time
import pymysql
# print(tf.__path__)
def ceshi(path):
# x = tf.placeholder(dtype=tf.float32, shape=[None, 100, 100, 3], name='input')
x = tf.placeholder(dtype=tf.float32, shape=[None, 100, 100, 3], name='input')
keep_prob = tf.placeholder(tf.float32)##是model.py中的dropout
# keep_prob = tf.compat.v1.placeholder(tf.float32) ##是model.py中的dropout
regulizer = tf.contrib.layers.l2_regularizer(0.0001)
output = models.inference(x, True, regulizer)
score = tf.nn.softmax(output)
f_cls = tf.argmax(score, 1)
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()
saver.restore(sess, tf.train.latest_checkpoint("C:\PythonWenjia\ceshitf1\paomo_model"))
conn1 = pymysql.connect(host='localhost', port=3306, user='root', passwd='2020328', db='evaluation',
charset='utf8')
cursor = conn1.cursor()
sql1 = "update result set stop=0 where id = 1"
upd_row = cursor.execute(sql1)
conn1.commit()
cursor.close()
conn1.close()
for i in os.listdir(path):
imgpath = os.path.join(path, i)
im = cv2.imread(imgpath)
im = im.astype('uint8')
im = cv2.resize(im, (100 , 100))# * (1. / 255)
im = np.expand_dims(im, axis=0)
#pred = sess.run(f_cls, feed_dict={x:im, keep_prob:1.0})
pred, _score = sess.run([f_cls, score], feed_dict={x:im, keep_prob:1.0})
#prob = round(np.max(_score))
prob = np.max(_score)
#print "{} flowers class is: {}".format(i, pred)
# print ("{} flowers class is: {}, score: {}".format(i, int(pred), prob))
a = int(pred)
# print(a)
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='2020328', db='evaluation',
charset='utf8')
cursor = conn.cursor()
sql_ = "select * from result;"
cursor.execute(sql_)
results = cursor.fetchone()
# print(results)
print(results[4])
stop = results[4]
if (stop == 1):
break
sql = "update result set Func1={value1} where id = 1".format( value1=a)
upd_row = cursor.execute(sql)
conn.commit()
cursor.close()
conn.close()
time.sleep(1)
sess.close()
if __name__ == '__main__':
path = r'C:\paomoImage\2021-07-11'
ceshi(path)
# ceshi(path)
泡沫 花分类示例类
于 2023-09-25 15:31:46 首次发布