Turi Create - 请使用dropna()删除行

时间:2018-05-21 16:13:38

标签: python-2.7 coreml turi

我遇到了Apple Turi Create和图像分类器的问题。我已经成功创建了一个包含22个类别的模型。我最近添加了5个类别,控制台正在给我错误警告

[16:30:30] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[16:30:30] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
Resizing images...
Performing feature extraction on resized images...
Premature end of JPEG file
Completed  512/1883
Completed 1024/1883
Completed 1536/1883
Completed 1883/1883
PROGRESS: Creating a validation set from 5 percent of training data. This may take a while.
      You can set ``validation_set=None`` to disable validation tracking.

[ERROR] turicreate.toolkits._main: Toolkit error: Target column has missing value.                    
Please use dropna() to drop rows with missing target values.
Traceback (most recent call last):
File "train.py", line 8, in <module>
model = tc.image_classifier.create(train_data, target='label', max_iterations=1000)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/turicreate/toolkits/image_classifier/image_classifier.py", line 132, in create
verbose=verbose)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/turicreate/toolkits/classifier/logistic_classifier.py", line 312, in create
seed=seed)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/turicreate/toolkits/_supervised_learning.py", line 397, in create
options, verbose)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/turicreate/toolkits/_main.py", line 75, in run
raise ToolkitError(str(message))
turicreate.toolkits._main.ToolkitError: Target column has missing value.                    

Please use dropna() to drop rows with missing target values.

完整的控制台日志如下所示:

import turicreate as tc

image_data = tc.image_analysis.load_images('images', with_path=True)

labels = ['A', 'B', 'C', 'D']

def get_label(path, labels=labels):
  for label in labels:
       if label in path:
           return label

image_data['label'] = image_data['path'].apply(get_label)

#import os
#image_data['label'] = image_data['path'].apply(lambda path:    os.path.dirname(path).split('/')[-1])

image_data.save('boxes.sframe')

image_data.explore()

我已将 turi coremltools 升级为lates版本,但我不知道应该在哪里实施 dropna()代码。我只找到了this reference并遵循了代码。

看起来像这样:

data.py

import turicreate as tc

data = tc.SFrame('boxes.sframe')
data.dropna()

train_data, test_data = data.random_split(0.8)

model = tc.image_classifier.create(train_data, target='label',    max_iterations=1000)

predictions = model.classify(test_data)

results = model.evaluate(test_data)

print "Accuracy           : %s" % results['accuracy']
print "Confusion Matrix   : \n%s" % results['confusion_matrix']

model.save('boxes.model')

train.py

{{1}}

如何删除所有空列和行? max_iterations = 1000 是否也会对错误产生影响?

感谢您的建议

1 个答案:

答案 0 :(得分:2)

data.dropna()没有到位,你需要写下来:data = data.dropna()
请参阅此处的文档https://apple.github.io/turicreate/docs/api/generated/turicreate.SFrame.dropna.html