示例#1
0
    def face_predict(self, image):
        #根据后端系统确定维度顺序
        if K.image_data_format() == 'channels_first' and image.shape != (
                1, 3, IMAGE_SIZE, IMAGE_SIZE):
            image = resize_image(image)  #尺寸必须与训练集一致。
            image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE))  #只针对1张图片来预测
        elif K.image_data_format() == 'channels_last' and image.shape != (
                1, 3, IMAGE_SIZE, IMAGE_SIZE):
            image = resize_image(image)
            image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))

        #图片归一化,先变为浮点数
        image = image.astype('float32')
        image /= 255

        #给出输入属于各个类别的概率,当前是二值类别,则该函数会给出输入图像
        #属于0和1的概率各是多少。
        result = self.model.predict_proba(image)
        print('result:', result)

        #给出类别预测:0或者1
        result = self.model.predict_classes(image)

        #返回类别预测结果
        return result[0]
示例#2
0
    def face_predict(self, image):
        # 依然是根据后端系统确定维度顺序
        if K.image_dim_ordering() == 'th' and image.shape != (1, 3, IMAGE_SIZE,
                                                              IMAGE_SIZE):
            image = resize_image(
                image)  # 尺寸必须与训练集一致都应该是IMAGE_SIZE x IMAGE_SIZE
            image = image.reshape(
                (1, 3, IMAGE_SIZE, IMAGE_SIZE))  # 与模型训练不同,这次只是针对1张图片进行预测
        elif K.image_dim_ordering() == 'tf' and image.shape != (1, IMAGE_SIZE,
                                                                IMAGE_SIZE, 3):
            image = resize_image(image)
            image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))

            # 浮点并归一化
        image = image.astype('float32')
        image /= 255

        # 给出输入属于各个类别的概率,我们是二值类别,则该函数会给出输入图像属于0和1的概率各为多少
        result = self.model.predict_proba(image)
        print('result:', result)

        # 给出类别预测:0或者1
        result = self.model.predict_classes(image)

        # 返回类别预测结果
        return result[0]
    def face_predict(self, image):    
        # 依然是根据后端系统确定维度顺序
        # 尺寸必须与训练集一致都应该是IMAGE_SIZE x IMAGE_SIZE
        if K.image_data_format() == 'channels_first' and image.shape != (1, 3, IMAGE_SIZE, IMAGE_SIZE):
            image = resize_image(image)                            
            image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))
            
        elif K.image_data_format() == 'channels_last' and image.shape != (1, IMAGE_SIZE, IMAGE_SIZE, 3):
              image = resize_image(image)
              image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))                    

        #image = img.reshape((1, 1, IMAGE_SIZE, IMAGE_SIZE))     
        # 浮点并归一化
        image = image.astype('float32')
        image /= 255.0
        
        # 则该函数会给出输入图像属于各个目标的概率
        result = self.model.predict(image)
        #print('result:', result )
        
        #找出概率最高的        
        max_index = np.argmax(result) 

        #第一个参数为概率最高的label的index,第二个参数为对应概率
        return max_index,result[0][max_index] 
    def face_predict(self, image):
        # 維度
        if K.image_dim_ordering() == 'th' and image.shape != (1, 3, IMAGE_SIZE,
                                                              IMAGE_SIZE):
            image = resize_image(image)
            image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE))
        elif K.image_dim_ordering() == 'tf' and image.shape != (1, IMAGE_SIZE,
                                                                IMAGE_SIZE, 3):
            image = resize_image(image)
            image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))

        # 數據標準化
        image = image.astype('float32')
        image /= 255

        # 每個圖片的機率
        result = self.model.predict_proba(image)
        print('result:', result)

        # 給出答案
        good = False
        for percent in result[0]:
            if percent >= 0.55:
                good = True

        result = self.model.predict_classes(image)

        # 輸出預測結果
        if good == True:
            outputresult = result[0]
        else:
            outputresult = -1
        print(outputresult)
        return outputresult
示例#5
0
    def face_predict(self, image):
        if K.image_dim_ordering() == 'th' and image.shape != (1, 3, IMAGE_SIZE,
                                                              IMAGE_SIZE):
            image = resize_image(image)
            image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE))
        elif K.image_dim_ordering == 'tf' and image.shape != (1, IMAGE_SIZE,
                                                              IMAGE_SIZE, 3):
            image = resize_image(image)
            image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))
        image = image.astype('float32')
        image /= 255
        result = self.model.predict_proba(image)
        print('result:', result)
        result = self.model.predict_classes(image)

        return result[0]
 def predict(self, image):
     image = resize_image(image)
     image_embedding = img_to_encoding(np.array([image]), facenet)
     label = self.model.predict(
         image_embedding
     )  # predict方法返回值是array of shape [n_samples],因此下面要用label[0]从array中取得数值,https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#sklearn.neighbors.KNeighborsClassifier.predict
     return label[0]
示例#7
0
    def face_predict(self, image):
        # 依然是根据后端系统确定维度顺序
        if k.image_dim_ordering() == 'th' and image.shape != (1, 3, IMAGE_SIZE,
                                                              IMAGE_SIZE):
            image = resize_image(image)
            image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE))
        elif k.image_dim_ordering() == 'tf' and image.shape != (1, IMAGE_SIZE,
                                                                IMAGE_SIZE, 3):
            image = resize_image(image)
            image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))

        # 浮点并归一化
        image = image.astype('float32')
        image /= 255.0
        # 给出输入属于各个类别的概率,这里是二值类别,输出属于0和1的概率各为多少

        # 给出类别预测:0或者1
        result = self.model.predict_classes(image)
        print("result----" + str(result))
        # 返回类别预测结果
        return result[0]
    def face_predict(self, image):    
            
#依然是根據後端系統確定維度順序
        if K.image_dim_ordering() == 'th' and image.shape != (1, 3, IMAGE_SIZE, IMAGE_SIZE):
            image = resize_image(image)                             #尺寸必須與訓練集一致都應該是IMAGE_SIZE x IMAGE_SIZE
            image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE))   #與模型訓練不同,這次只是針對1張圖片進行預測 
        elif K.image_dim_ordering() == 'tf' and image.shape != (1, IMAGE_SIZE, IMAGE_SIZE, 3):
            image = resize_image(image)
            image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))                    

            #浮点并归一化
        image = image.astype('float32')
        image /= 255
        
            #給出輸入屬於各個類別的概率,我們是二值類別,則該函數會給出輸入圖像屬於0和1的概率各為多少
        result = self.model.predict_proba(image)
        print('result:', result)
        
            #给出類別預測:0或者1
        result = self.model.predict_classes(image)        

            #返回類別預測結果
        return result[0]
示例#9
0
    def face_predict(self, image):
        image = resize_image(image)
        image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))

        # 浮点并归一化
        image = image.astype('float32')
        image /= 255

        # 给出输入属于各个类别的概率,我们是二值类别,则该函数会给出输入图像属于0和1的概率各为多少
        result = self.model.predict(image)
        #print('result:', result)
        gender_class = np.argmax(result)
        print(gender_class)

        # 返回类别预测结果
        return gender_class
    def face_predict(self, image):
        image = resize_image(image)
        image = image.reshape((1, IMAGE_SIZE, IMAGE_SIZE, 3))

        # 浮点并归一化
        image = image.astype('float32')
        image /= 255

        # 给出输入属于各个类别的概率,我们是二值类别,则该函数会给出输入图像属于0和1的概率各为多少
        result = self.model.predict_proba(image)
        print('result:', result)

        # 给出类别预测:0或者1
        result = self.model.predict_classes(image)

        print(result)
        # 返回类别预测结果
        return result[0]
示例#11
0
 def predict(self, image):
     image = resize_image(image)
     image_embedding = img_to_encoding(np.array([image]), facenet)
     label = self.model.predict(image_embedding)
     return label[0]