halcon18.05--------深度学习----------MNIST

①preprocess

dev_update_off ()
dev_close_window ()
WindowWidth := 800
WindowHeight := 600
dev_open_window_fit_size (0, 0, WindowWidth, WindowHeight, -1, -1, WindowHandle)

*mnist数据集不(28X28)
*读入的是训练集(训练+验证)
RawTrainDataFolder:='D:/kliu/DL/halcon_deeplearning/mnist_copy/train_images/'
read_dl_classifier_data_set (RawTrainDataFolder, 'last_folder', TrainImageFiles, TrainGroundTruthLabels, TrainLabelIndices, Classes)
*读入的是测试集
RawTestDataFolder:='D:/kliu/DL/halcon_deeplearning/mnist_copy/test_images/'
read_dl_classifier_data_set (RawTestDataFolder, 'last_folder', TestImageFiles, TestGroundTruthLabels, TestLabelIndices, Classes)

read_dl_classifier ('pretrained_dl_classifier_compact.hdl', DLClassifierHandle)
SampleImageFile := TrainImageFiles[1302]
read_image (SampleImage, SampleImageFile)

*************************************************预处理
*----------------预处理训练集(训练+验证)
Preprocessed_train_Folder:='mnist_train_preprocessed'
file_exists (Preprocessed_train_Folder, FileExists)
RemovePreprocessingAfterExample := true
*当存在预处理的文件夹时,选择是否覆盖
OverwritePreprocessingFolder := true
if (not FileExists or OverwritePreprocessingFolder)
    *如果存在预处理的文件夹,则进行删除
    if (FileExists)
        remove_dir_recursively (Preprocessed_train_Folder)
    endif
    *创建预处理的文件夹并创建9个类别的子文件夹
    make_dir (Preprocessed_train_Folder)
    for I := 0 to |Classes| - 1 by 1
        make_dir (Preprocessed_train_Folder + '/' + Classes[I])
    endfor
    *定义输出的预处理文件的名称
    parse_filename (TrainImageFiles, BaseNames, Extensions, Directories)
    ObjectFilesOut := Preprocessed_train_Folder + '/' + TrainGroundTruthLabels + '/' + BaseNames + '.hobj'
    *检查文件是否有重复的情况
    check_output_file_names_for_duplicates (TrainImageFiles, ObjectFilesOut)
    for I := 0 to |TrainImageFiles| - 1 by 1
        read_image (Image, TrainImageFiles[I])

        preprocess_dl_pills_example (Image, TrainImagePreprocessed, DLClassifierHandle)
        *保存预处理的文件
        write_object (TrainImagePreprocessed, ObjectFilesOut[I])
        dev_disp_preprocessing_progress (I, TrainImageFiles, Preprocessed_train_Folder, WindowHandle)
    endfor
endif

②train
③evaluate
④inference
https://download.csdn.net/download/qq_22904277/10577346

你可能感兴趣的:(halcon,deep,learning)