一些烧瓶图像不显示

时间:2018-08-21 06:12:28

标签: image flask display

我正在使用Flask框架,并且已经在测试一些深度学习模型,并且正在尝试部署它们。我创建了一个静态文件夹和一个相应的html文件。它加载了80%的图像,但是由于某些原因,并非所有图像都已加载。当它们未装入烧瓶时,它们会给出图像断裂错误,但有时这些图像装入烧瓶中,而有时则不会。我想知道烧瓶是否可以始终如一地显示所有图像。 这是下面的代码:

@app.route('/')
def index():
    return render_template('gender_classification.html')
@app.route('/predict', methods = ['POST'])
def predict():
    if request.method == 'POST':
        encoded_original = request.files['picture']
        encoded = base64.b64encode(encoded_original.read())
        decoded = base64.b64decode(encoded)
        image = Image.open(io.BytesIO(decoded))
        preprocessed_image = preprocess_image(image, target_size=(150, 
150))
        prediction = make_predictions(preprocessed_image)
        response = {
            'prediction': {
                'male': prediction[0][0],
                'female': prediction[0][1]
            }}

        target = os.path.join(app_root, 'static/')
        # target = os.path.join(APP_ROOT, 'static/')
        print(target)
        if not os.path.isdir(target):
            os.mkdir(target)
        else:
            print("Couldn't create upload directory: 
{}".format(target))
        print(request.files.getlist("file"))
        for upload in request.files.getlist("picture"):
            filename = upload.filename
            destination = "/".join([target, filename])
            print("Accept incoming file:", filename)
            print("Save it to:", destination)
            upload.save(destination)

        return render_template("gender_results.html",encoded = 
response, image_name=filename)

This is an image of when the picture is correctly retrieved This is an image of where the picture is not correctly retrieved. 这没有任何意义,因为图像已下载到静态文件夹中,以后我可以查看它们。

0 个答案:

没有答案
相关问题