这是我的代码:
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' `我有这样的错误:
File "<ipython-input-31-35ebf5fa8bf7>", line 7
prediction = 'dog'
^
IndentationError: expected an indented block有谁可以帮我?
发布于 2018-12-03 21:37:06
您的代码没有正确缩进:
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' 发布于 2018-12-03 21:38:33
python中的块作用于缩进。请参阅:
"https://www.python.org/dev/peps/pep-0008/#indentation“
Your code should be like:
if result[0][0] == 1:
<4 spaces>prediction = 'dog'
else:
<4 spaces>prediction = 'cat' 发布于 2018-12-03 21:38:52
在Python中,缩进很重要。因此,您需要缩进块(例如,放入if中的内容):
if result[0][0] == 1:
prediction = 'dog'
#...https://stackoverflow.com/questions/53595043
复制相似问题