首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IndentationError:需要缩进块- Python机器学习猫/狗

IndentationError:需要缩进块- Python机器学习猫/狗
EN

Stack Overflow用户
提问于 2018-12-03 21:35:02
回答 4查看 306关注 0票数 1

这是我的代码:

代码语言:javascript
复制
test_image = image.load_img('dataset/single_prediction/cat_or_dog_1.jpg', target_size = (64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = classifier.predict(test_image)
training_set.class_indices
if result[0][0] == 1:
prediction = 'dog'
else:
prediction = 'cat' `

我有这样的错误:

代码语言:javascript
复制
File "<ipython-input-31-35ebf5fa8bf7>", line 7
prediction = 'dog'
         ^
IndentationError: expected an indented block

有谁可以帮我?

EN

回答 4

Stack Overflow用户

发布于 2018-12-03 21:37:06

您的代码没有正确缩进:

代码语言:javascript
复制
test_image = image.load_img('dataset/single_prediction/cat_or_dog_1.jpg', target_size = (64, 64))
test_image = image.img_to_array(test_image)
 test_image = np.expand_dims(test_image, axis = 0)
result = classifier.predict(test_image)
training_set.class_indices
if result[0][0] == 1:
    prediction = 'dog'
else:
    prediction = 'cat' 
票数 1
EN

Stack Overflow用户

发布于 2018-12-03 21:38:33

python中的块作用于缩进。请参阅:

"https://www.python.org/dev/peps/pep-0008/#indentation

代码语言:javascript
复制
Your code should be like:  
if result[0][0] == 1:  
<4 spaces>prediction = 'dog'  
else:  
<4 spaces>prediction = 'cat'  
票数 0
EN

Stack Overflow用户

发布于 2018-12-03 21:38:52

在Python中,缩进很重要。因此,您需要缩进块(例如,放入if中的内容):

代码语言:javascript
复制
if result[0][0] == 1:
  prediction = 'dog'
#...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53595043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档