为什么会报错? - V2EX
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 4655 次点击
    这是一个创建于 2115 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #-*-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
    < href="/member/Trim21" class="dark">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     Solana     2980 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 13:32 PVG 21:32 LAX 06:32 JFK 09:32
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86