当我在浏览器中打开链接 0.0.0.0:5000 时,我总是在浏览器上收到消息“无法访问此站点”,代码似乎正在运行,因为我在控制台上收到此消息
在http://0.0.0.0:5000/ 上运行(按 CTRL+C 退出)
这是我正在使用的代码
from flask import Flask, render_template, request
from scipy.misc import imsave, imread, imresize
import numpy as np
import keras.models
import re
import sys
import os
from load import *
sys.path.append(os.path.abspath('./model'))
app = Flask(__name__)
global model, graph
model, graph = init()
def convertImage(imData):
imgstr = re.search(r'base64(.*'.imData).group(1)
with open('output.png', 'wb') as output:
output.write(imgstr.decode('base64'))
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict', methods=['GET', 'POST'])
def predict():
imData = request.get_data()
convertImage(imData)
x = imread('output.png', mode = 'L') …Run Code Online (Sandbox Code Playgroud) 我尝试执行此代码,但出现以下错误,我在随机函数中出现错误,但我不知道如何解决,请帮助我。
def load_data(sample_split=0.3, usage='Training', to_cat=True, verbose=True,
classes=['Angry','Happy'], filepath='C:/Users/Oussama/Desktop/fer2013.csv'):
df = pd.read_csv(filepath)
# print df.tail()
# print df.Usage.value_counts()
df = df[df.Usage == usage]
frames = []
classes.append('Disgust')
for _class in classes:
class_df = df[df['emotion'] == emotion[_class]]
frames.append(class_df)
data = pd.concat(frames, axis=0)
rows = random.sample(data.index, int(len(data)*sample_split))
data = data.ix[rows]
print ('{} set for {}: {}'.format(usage, classes, data.shape))
data['pixels'] = data.pixels.apply(lambda x: reconstruct(x))
x = np.array([mat for mat in data.pixels]) # (n_samples, img_width, img_height)
X_train = x.reshape(-1, 1, x.shape[1], x.shape[2])
y_train, new_dict = …Run Code Online (Sandbox Code Playgroud) 我有一个文件列表,我想把它分成 3 部分:训练、验证和测试。我试过这段代码,我不知道它是否正确。
files = glob.glob("/dataset/%s/*" % emotion)
training = files[:int(len(files)*0.8)] #get first 80% of file list
validation = files[-int(len(files)*0.1):] #get middle 10% of file list
testing = files[-int(len(files)*0.1):] #get last 10% of file list
Run Code Online (Sandbox Code Playgroud)
我不确定测试列表是重复的还是文件列表的最后 10% 是正确的。
我想将这个 numpy 图像数组的顺序更改为 channel_last training_data : (2387, 1, 350, 350) to (2387,350,350,1) validation_data : (298, 1, 350, 350) to (298, 350, 350) , 1) testing_data : (301, 1, 350, 350) 到 (301, 350, 350, 1)
我试过这个,但它不起作用
np.rollaxis(training_data,0,3).shape
np.rollaxis(validation_data,0,3).shape
np.rollaxis(testing_data,0,3).shape
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行python代码,但出现错误,我不熟悉python,所以我不知道如何调试代码。请帮助,谢谢。我刚刚在以下网站上找到了此代码:http : //www.paulvangent.com/2016/04/01/emotion-recognition-with-python-opencv-and-a-face-dataset/ 这是代码:
import cv2
import glob
import random
import numpy as np
emotions = ["neutral", "anger", "contempt", "disgust", "fear", "happy", "sadness", "surprise"] #Emotion list
fishface = cv2.face.createFisherFaceRecognizer() #Initialize fisher face classifier
data = {}
def get_files(emotion): #Define function to get file list, randomly shuffle it and split 80/20
files = glob.glob("dataset\\%s\\*" %emotion)
random.shuffle(files)
training = files[:int(len(files)*0.8)] #get first 80% of file list
prediction = files[-int(len(files)*0.2):] #get last 20% of file list
return training, prediction
def make_sets():
training_data …Run Code Online (Sandbox Code Playgroud)