Beispiel #1
0
        shutil.copy(image_filename_source, image_filename_dest)

        print(image_filename_dest)

    print('read csv file, copy subclass10 to dir OK!')


#region preprocess 512

# dir_original = '/tmp2/SubClass10/original/'
dir_original = dir_dest
dir_preprocess512 = '/tmp2/SubClass10/preprocess512/'

if DO_PREPROCESS:
    from LIBS.ImgPreprocess.my_preprocess_dir import do_process_dir
    do_process_dir(dir_original, dir_preprocess512, image_size=512)
    print('preprocess OK!')

#endregion

#region crop optic disc 112

dir_source = dir_preprocess512
dir_dest = '/tmp2/SubClass10_new/Crop_optic_disc_112/'

crop_optic_disc_dir(dir_source=dir_source, dir_dest=dir_dest, server_port=21000, mask=True)

print('crop optic disc 112 OK!')

#endregion
import os, sys, csv
import pandas as pd
from sklearn.utils import shuffle
from LIBS.DataPreprocess import my_data

DO_PREPROCESS = True
GENERATE_CSV = True

from LIBS.ImgPreprocess.my_preprocess_dir import do_process_dir

dir_original = '/media/ubuntu/data2/其它数据集/筛查集//original'
dir_preprocess = '/media/ubuntu/data2/其它数据集/筛查集/preprocess384'

if DO_PREPROCESS:
    do_process_dir(dir_original,
                   dir_preprocess,
                   image_size=384,
                   add_black_pixel_ratio=0.02)

filename_csv = 'screening.csv'

current_dir = os.path.abspath(os.path.dirname(__file__))
filename_csv = os.path.join(current_dir, filename_csv)

from LIBS.DataPreprocess.my_data import write_csv_dir_nolabel

if GENERATE_CSV:
    write_csv_dir_nolabel(filename_csv, dir_preprocess)

print('OK')
    filename_csv = os.path.abspath(os.path.join(sys.path[0], "..",
                                'datafiles', predict_type_name + '.csv'))

    filename_csv = os.path.abspath(os.path.join(sys.path[0], "..",
                        'datafiles', 'Subclass_0.3_a.csv'))

    dir_dest_confusion = os.path.join(DIR_DEST_BASE, predict_type_name, 'confusion_matrix', 'files')
    dir_dest_predict_dir = os.path.join(DIR_DEST_BASE, predict_type_name, 'dir')
    pkl_prob = os.path.join(DIR_DEST_BASE, predict_type_name + '_prob.pkl')
    pkl_confusion_matrix = os.path.join(DIR_DEST_BASE, predict_type_name + '_cf.pkl')

    if DO_PREPROCESS:
        from LIBS.ImgPreprocess import my_preprocess_dir
        image_size = 512
        my_preprocess_dir.do_process_dir(dir_original, dir_preprocess, image_size=image_size)

    if GEN_CSV:
        if not os.path.exists(os.path.dirname(filename_csv)):
            os.makedirs(os.path.dirname(filename_csv))

        if GET_LABELS_FROM_DIR:
            dict_mapping = {}
            for i in range(30):
                dict_mapping[str(i)] = str(i)

            my_data.write_csv_based_on_dir(filename_csv, dir_preprocess, dict_mapping)
        else:
            my_data.write_csv_dir_nolabel(filename_csv, dir_preprocess)

Beispiel #4
0
import sys, os
import pandas as pd
import csv
from LIBS.DataPreprocess.my_data import get_big_classes

DO_PREPROCESS = False

dir_original = '/media/ubuntu/data1/multi_labels_2919_1_15/'
dir_preprocess = '/home/ubuntu/multi_labels_2919_1_15/preprocess384/'
if DO_PREPROCESS:
    from LIBS.ImgPreprocess.my_preprocess_dir import do_process_dir
    do_process_dir(dir_original, dir_preprocess, image_size=299)


def gen_subclass_csv(filename_csv_all,
                     filename_csv_subclass,
                     subclass_no,
                     one_one_class=True):
    str_subclass_no = str(subclass_no)

    df = pd.read_csv(filename_csv_all)

    if os.path.exists(filename_csv_subclass):
        os.remove(filename_csv_subclass)

    with open(filename_csv_subclass, 'w', newline='') as csvfile:
        csv_writer = csv.writer(csvfile, delimiter=',')
        csv_writer.writerow(['images', 'labels'])

        for i, row in df.iterrows():
            labels = row["labels"]
Beispiel #5
0
DO_PREPROCESS = True

GEN_CSV = True

COMPUTE_DIR_FILES = True

DIR_DEST_BASE = '/tmp5/测试集分子类/results'

dir_original = '/tmp5/测试集分子类/original'
dir_preprocess = '/tmp5/测试集分子类/preprocess384'

if DO_PREPROCESS:
    from LIBS.ImgPreprocess import my_preprocess_dir
    image_size = 384
    my_preprocess_dir.do_process_dir(dir_original,
                                     dir_preprocess,
                                     image_size=image_size,
                                     add_black_pixel_ratio=0.02)

    print('Preprocess OK')

for subclass_type in ['0.1', '0.2', '1', '2', '29']:
    # for subclass_type in ['0.1', '0.2', '1', '2', '5', '15', '29']:

    dir_original_subclass = os.path.join(dir_original, subclass_type)
    dir_preprocess_subclass = os.path.join(dir_preprocess, subclass_type)

    predict_type_name = 'Subclass' + subclass_type
    filename_csv = os.path.join(DIR_DEST_BASE, predict_type_name + '.csv')

    if GEN_CSV:
        if not os.path.exists(os.path.dirname(filename_csv)):