AAnight
AAnight
采纳率50%
2021-03-04 21:33

Tensorflow中的代码缩进问题

import re
import numpy as np
from PIL import Image

from sklearn.model_selection import train_test_split
from keras import backend as K
from keras.layers import Activation
from keras.layers import Input, Lambda, Dense, Dropout, Convolution2D, MaxPooling2D, Flatten
from keras.models import Sequential, Model
from keras.optimizers import RMSprop

代码如上,运行时会提示缩进错误,但是用notepad++检查并没有发现空格和TAB混用的问题,请问这种是什么问题呢?

报错:

Traceback (most recent call last):

  File "D:\anaconda\envs\tensorflow2\lib\site-packages\IPython\core\interactiveshell.py", line 3427, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-1-73b060c2cb86>", line 5, in <module>
    from keras import backend as K

  File "D:\anaconda\envs\tensorflow2\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils

  File "D:\anaconda\envs\tensorflow2\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils

  File "D:\anaconda\envs\tensorflow2\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K

  File "D:\anaconda\envs\tensorflow2\lib\site-packages\keras\backend\__init__.py", line 1, in <module>
    from .load_backend import epsilon

  File "D:\anaconda\envs\tensorflow2\lib\site-packages\keras\backend\load_backend.py", line 90, in <module>
    from .tensorflow_backend import *

  File "D:\anaconda\envs\tensorflow2\lib\site-packages\keras\backend\tensorflow_backend.py", line 508
    _LOCAL_DEVICES = [x.name for x in devices]
                                              ^
IndentationError: unindent does not match any outer indentation level
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • ProfSnail ProfSnail 1月前

    检查一下报错的最后一个文件的第508行。

    D:\anaconda\envs\tensorflow2\lib\site-packages\keras\backend\tensorflow_backend.py

    是否出现了缩进不对齐的情况。

    包的源码出现了缩进不对齐的这种情况不太常见,但是也有可能会出现。可以尝试查看一下。

    点赞 评论 复制链接分享

为你推荐