泡沫 花分类示例类

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值