Python: Write Image Classification Predictions to a Text File
To write the predictions to a txt file, you can use the following code:\n\npython\nfile_path = 'predictions.txt' # specify the path of the txt file\n\nwith open(file_path, 'w') as file:\n for i in range(len(predictions)):\n label = predictions[i]\n probs = top5_probs[i].tolist()\n indices = top5_indice[i].tolist()\n \n file.write(f'Prediction: {label}\n')\n file.write('Top 5 Probabilities and Indices:\n')\n for j in range(len(probs)):\n file.write(f'Probability: {probs[j]}, Index: {indices[j]}\n')\n file.write('\n')\n\n\nThis code will write the predictions, top 5 probabilities, and indices to the txt file, with each line representing a prediction.
原文地址: https://www.cveoy.top/t/topic/qfUt 著作权归作者所有。请勿转载和采集!