//Save the image names and corresponding labels into a .txt file for Caffe/CNTK/TensorFlow void QxMainWindow::saveLabelFile(const QString& strFilePath, QxDecodeOptionDlg::ApplicationType appType) { // There's no need to store label files for DIGITS. if (appType == QxDecodeOptionDlg::DIGITS) { return; } // Use a local file to save path of images and corresponding labels. QString strLabelFileName = strFilePath + "/" + g_LabelFileName; QFile labelFile(strLabelFileName); if (!labelFile.open(QIODevice::WriteOnly | QIODevice::Text)) { QString strTitle("Open file error"); QString strMessage("Can not open label file:\n"); strMessage.append(strLabelFileName); strMessage.append("\nMaybe you do not have permission to create a new file in the selected folder?"); strMessage.append("\nOr maybe there is a Read-Only file named \"").append(g_LabelFileName).append("\" in the selected folder?"); QMessageBox::critical(this, strTitle, strMessage, QMessageBox::Ok); return; } QTextStream textStream(&labelFile); for (QMap<QString, quint32>::iterator itr = m_ImageLabelMap.begin(); itr != m_ImageLabelMap.end(); ++itr) { textStream << getLabelInfo(itr.key(), itr.value(), appType) << "\n"; } labelFile.close(); }
void DSSMReader<ElemType>::WriteLabelFile() { // write out the label file if they don't have one if (!m_labelFileToWrite.empty()) { if (m_mapIdToLabel.size() > 0) { File labelFile(m_labelFileToWrite, fileOptionsWrite | fileOptionsText); for (int i = 0; i < m_mapIdToLabel.size(); ++i) { labelFile << m_mapIdToLabel[i] << '\n'; } fprintf(stderr, "label file %ls written to disk\n", m_labelFileToWrite.c_str()); m_labelFileToWrite.clear(); } else if (!m_cachingWriter) { fprintf(stderr, "WARNING: file %ls NOT written to disk yet, will be written the first time the end of the entire dataset is found.\n", m_labelFileToWrite.c_str()); } } }