first of all I'd like to wish you a Happy New Year! To introduce myself: I'm a Digital Humanities student from Germany and we are currently conducting a small study at my university, where we are trying to predict music genres from their respective album covers with machine learning algorithms. Right now we don't know yet, which image features are useful for our image classification, so I stumbled upon Clarifai and it looks very exciting and we want to test object recognition as one possible classification feature!
As a programming beginner, I had some problems getting a working python script together. However, it works perfectly when only one batch is processed, but as soon as I start to process more than one batch, I'm getting Index Errors (and our test database contains 500 images, so I really need to process more than one batch). What I'm doing in my code is writing the results of the prediction into a JSON-File. After that I'm extracting the 5 most probable recognised objects into a CSV file, so that it looks like this:
I tested a small sample with 14 images and a batch_size of 7, so that I force my script to process more than one batch. I hope I'm not wasting your time, because my question/problem is probably not Clarifai-specific, but a beginner's coding mistake.
Here is my code snippet, that's responsible for writing and extracting the data:
while (counter < total_files):
print ("Processing batch " + str(index+1))
for x in range(counter,counter+batch_size):
model = app.models.get('general-v1.3')
data = model.predict(imageList)
with codecs.open ('data.json', 'w', encoding='utf-8') as outfile:
json.dump(data,outfile) #All Data
file = codecs.open('extract.csv', 'w', encoding='utf-8')
split_paths = [os.path.basename(p) for p in files]
for x in range(counter,counter+batch_size): #write filename and top 5 objects into CSV file
while i < 5:
tags = data ['outputs'] [x] ['data'] ['concepts'][i]['name'] #error appears in this line
file.write(tags + "\n")
i = i+1
Thank you in advance!