代码之家  ›  专栏  ›  技术社区  ›  Aakash aggarwal

类型错误:无法将feed_dict key解释为张量

  •  0
  • Aakash aggarwal  · 技术社区  · 6 年前

    我正在使用线程方法使多个客户端到一个服务器。我用一个带有resnet50的预训练模型来预测一些事情。 我的预测代码是

    def prediction(array):
        array = np.array(array , dtype = np.float64)
        array = np.reshape(array, (1,224,224,3))
        #print(array.shape)
        a = preprocess_input(array)
        model = ResNet50(weights='imagenet', include_top=False)
        features = model.predict(a)
        #print(features.shape)
        image = features.reshape(features.shape[0] , -1)
        #print(image.shape)
        loaded_model = keras.models.load_model('RESNET50.h5')
        y_predict = loaded_model.predict(image)
        if y_predict[0][0] > y_predict[0][1]:
            return "Non-Nude"
        else:
            return "Nude"
        K.clear_session()
    

    我的服务器代码是

    class ClientThread(Thread):
    
        def __init__(self,ip,port,sock):
            Thread.__init__(self)
            self.ip = ip
            self.port = port
            self.sock = sock
            print("New thread started for "+ip+":"+str(port))
    
        def run(self):
            send_one_message(self.sock, self.ip)
            send_one_message(self.sock, self.port)
            data = recv_one_message(self.sock)
            #print("data recevied")
            res = prediction(data)
            send_one_message(self.sock, res)
    
    
    TCP_IP = ''
    TCP_PORT = 12001
    tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    tcpsock.bind((TCP_IP, TCP_PORT))
    threads = []
    
    while True:
        tcpsock.listen(5)
        print("Waiting for incoming connections...")
        (conn, (ip,port)) = tcpsock.accept()
        print('Got connection from ', (ip,port))
        newthread = ClientThread(ip,port,conn)
        newthread.start()
        threads.append(newthread)
    
    for t in threads:
        t.join()
    

    它能够连接多个客户机,但它只对第一个连接的客户机和每一个连接的客户机给出精确的预测 enter image description here

    谢谢你的帮助!

    0 回复  |  直到 6 年前