V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
1521815837
V2EX  ›  Python

为什么会报错?

  •  
  •   1521815837 · 2019-12-26 03:37:39 +08:00 · 3872 次点击
    这是一个创建于 1554 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #-*-coding:utf-8-*-
    from flask import Flask,render_template,request,jsonify
    from flask_uploads import configure_uploads,UploadSet
    import os,base64
    import time
    import random
    import tensorflow as tf
    from cnnmodel import cnnModel
    import pickle
    import numpy as np
    from PIL import Image

    app = Flask(__name__)
    base=os.path.dirname(os.path.abspath(__file__))
    base = os.path.join(base,'static')
    app.config['UPLOADS_DEFAULT_DEST']=base
    photo=UploadSet()
    configure_uploads(app,photo)
    feed = '1234567890abcdefghijklmnopqrstuvwxyz'

    def predict(data):
    model = tf.keras.models.load_model('static/cnn_model.h5')
    predicton = model.predict(data)
    index = tf.math.argmax(predicton[0].numpy)
    return label_names_dict[index]

    @app.route('/')
    def index():
    return render_template('index.html')

    @app.route('/api', methods=['POST'])
    def modeltest():
    if request.method == "POST":
    id = ''.join(random.sample(feed,16))
    photo.save(request.files['file'],time.strftime("%Y-%m-%d",time.localtime()),id+'.png')
    file ='static/batches.meta'
    patch_bin_file = open(file,'rb')
    label_names_dict = pickle.load(patch_bin_file)['label_names']
    img = Image.open('static/file'+time.strftime("%Y-%m-%d",time.localtime()+'/'+id+'.png')
    r,g,b = img.split()
    r_arr = np.arry(r)
    g_arr = np.arry(g)
    b_arr = np.arry(b)
    img = np.concatenate((r_arr,_arr,b_arr))
    image = img.reshape([1,32,32,3])/255
    return predict(image)

    if __name__ == "__main__":
    app.run()
    求大佬指点
    10 条回复    2020-01-07 11:04:28 +08:00
    casparchen
        1
    casparchen  
       2019-12-26 05:56:43 +08:00
    python 需要缩进,缩进错了当然报错。
    Trim21
        2
    Trim21  
       2019-12-26 06:02:52 +08:00 via Android
    233 除了缩进以外你可能还需要补充的信息
    你期望的代码行为
    实际的代码行为
    itskingname
        3
    itskingname  
       2019-12-26 08:21:50 +08:00 via iPhone
    请搜索:提问的艺术。你这样直接甩一大堆代码上来,不讲上下文,不讲你期望实现的效果,没有行号,别人怎么帮你回答?
    markgor
        4
    markgor  
       2019-12-26 08:57:38 +08:00
    因為錯了
    hbolive
        5
    hbolive  
       2019-12-26 09:03:32 +08:00
    @itskingname 在他看来,大佬扫一眼,就该知道问题所在。。
    vhysug01
        6
    vhysug01  
       2019-12-26 09:07:15 +08:00
    讲真,我看不懂这在写什么
    TuringGunner
        7
    TuringGunner  
       2019-12-26 09:14:15 +08:00
    代码乱七八糟,错误信息也不给,要干嘛也不说

    这咋看嘛
    shyrock
        8
    shyrock  
       2019-12-26 09:37:01 +08:00
    有请大佬来脑运一遍代码,自行提取错误信息?
    swordspoet
        9
    swordspoet  
       2019-12-26 13:46:34 +08:00
    把代码粘贴到了 IDE,调整了一下缩进,发现报了一个错误:

    ```
    r,g,b = img.split()
    ^
    SyntaxError: invalid syntax
    ```
    leiz
        10
    leiz  
       2020-01-07 11:04:28 +08:00
    我看出来了,但是我不告诉你
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3914 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:28 · PVG 18:28 · LAX 03:28 · JFK 06:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.