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): 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 face_predict(self, image): #Check the order of parameters if K.image_dim_ordering() == 'th' and image.shape != (1, 3, IMAGE_SIZE, IMAGE_SIZE): image = resize_image(image) #change it size to the same as train_set 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 #ouput predict value result = self.model.predict_proba(image) print('result:', result) result = self.model.predict_classes(image) return result[0]
def predict(base64_file): if global_model is None: return 'error' image = ld.resize_image(base64_file, size, size) # print(image, file=sys.stdout) result = { 'predictions': [] } predictions = global_model.predict([image]) for i, label in enumerate(label_array): result['predictions'].append({ 'label': label, 'proba': predictions[0][i].item() }) return json.dumps(result)
from tflearn.layers.core import input_data, dropout, fully_connected from tflearn.layers.conv import conv_2d, max_pool_2d from tflearn.layers.estimator import regression from tflearn.data_preprocessing import ImagePreprocessing from tflearn.data_augmentation import ImageAugmentation import numpy as np import loadData as ld import reseau as re path = sys.argv[1] fileName = path.split('/')[len(path.split('/'))-1] folderPath = path[:len(path)-len(fileName)-1] size = settings.size ld.resize_image(folderPath, fileName, size, size) extension = fileName.split('.')[len(fileName.split('.'))-1] img = cv2.imread('./data/'+fileName[:len(fileName)-len(extension)]+'jpg').astype(np.float32, casting='unsafe') model = re.getReseau() model.load("dataviz-classifier.tfl") prediction = model.predict([img]) print(prediction)