• 大小: 8.06MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-18
  • 语言: Python
  • 标签:

资源简介

用于分类高分辨率全幻灯片图像的滑动窗框架,通常是显微镜或组织病理学图像

资源截图

代码片段和文件信息

# DeepSlide
# Jason Wei Behnaz Abdollahi Saeed Hassanpour

#This splits the train val and test data.

import config
from utils import *

#main function
#note that we want the validation and test sets to be balanced
def split(all_wsi train_folder val_folder test_folder val_split test_split keep_orig_copy labels_train labels_val labels_test):

head = ‘cp‘ if keep_orig_copy else ‘mv‘ #based on whether we want to move or keep the files

#create folders
for folder in [train_folder val_folder test_folder]:
subfolders = [join(folder _class) for _class in config.classes]
for subfolder in subfolders:
confirm_output_folder(subfolder) 

train_img_to_label = {}
val_img_to_label = {}
test_img_to_label = {}

#sort the images and move/copy them appropriately
subfolder_paths = get_subfolder_paths(all_wsi)
for subfolder in subfolder_paths:

image_paths = get_image_paths(subfolder)
assert len(image_paths) > val_split + test_split #make sure we have enough slides in each class

#assign training test and val images
test_idx = len(image_paths) - test_split
val_idx = test_idx - val_split
train_images = image_paths[:val_idx]
val_images = image_paths[val_idx:test_idx]
test_images = image_paths[test_idx:]
print(‘class ‘+subfolder.split(‘/‘)[-1]+ ‘:‘ ‘#train=‘+str(len(train_images)) ‘#val=‘+str(len(val_images)) ‘#test=‘+str(len(test_images)))

#move train
for train_image in train_images:
output_path = ‘/‘.join([train_folder ‘/‘.join(train_image.split(‘/‘)[1:])])
os.system(‘ ‘.join([head train_image output_path]))
img_name = train_image.split(‘/‘)[-1]
img_class = train_image.split(‘/‘)[-2]
train_img_to_label[img_name] = img_class
#writer_train.write(img_name + ‘‘ + img_class + ‘\n‘)

#move val
for val_image in val_images:
output_path = ‘/‘.join([val_folder ‘/‘.join(val_image.split(‘/‘)[1:])])
os.system(‘ ‘.join([head val_image output_path]))
img_name = val_image.split(‘/‘)[-1]
img_class = val_image.split(‘/‘)[-2]
val_img_to_label[img_name] = img_class
#writer_val.write(img_name + ‘‘ + img_class + ‘\n‘)

#move test
for test_image in test_images:
output_path = ‘/‘.join([test_folder ‘/‘.join(test_image.split(‘/‘)[1:])])
os.system(‘ ‘.join([head test_image output_path]))
img_name = test_image.split(‘/‘)[-1]
img_class = test_image.split(‘/‘)[-2]
test_img_to_label[img_name] = img_class
#writer_test.write(img_name + ‘‘ + img_class + ‘\n‘)


#for making the csv files
writer_train = open(labels_train ‘w‘)
writer_train.write(‘imggt\n‘)
for img in sorted(train_img_to_label.keys()):
writer_train.write(img + ‘‘ + train_img_to_label[img] + ‘\n‘)

writer_val = open(labels_val ‘w‘)
writer_val.write(‘imggt\n‘)
for img in sorted(val_img_to_label.keys()):
writer_val.write(img + ‘‘ + val_img_to_label[img] + ‘\n‘)

writer_test = open(labels_test ‘w‘)
writer_test.write(‘imggt\n‘)
for img in sorted(test_img_to_label.keys()):
writer_test.writ

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-07-15 21:29  deepslide-master\
     文件          70  2019-07-15 21:29  deepslide-master\.gitignore
     文件       35149  2019-07-15 21:29  deepslide-master\LICENSE
     文件        7253  2019-07-15 21:29  deepslide-master\README.md
     目录           0  2019-07-15 21:29  deepslide-master\code\
     文件        3457  2019-07-15 21:29  deepslide-master\code\1_split.py
     文件         895  2019-07-15 21:29  deepslide-master\code\2_process_patches.py
     文件         736  2019-07-15 21:29  deepslide-master\code\3_train.py
     文件         655  2019-07-15 21:29  deepslide-master\code\4_test.py
     文件         430  2019-07-15 21:29  deepslide-master\code\5_grid_search.py
     文件         503  2019-07-15 21:29  deepslide-master\code\6_visualize.py
     文件         536  2019-07-15 21:29  deepslide-master\code\7_final_test.py
     文件        4468  2019-07-15 21:29  deepslide-master\code\config.py
     文件         245  2019-07-15 21:29  deepslide-master\code\run_all.sh
     文件        3100  2019-07-15 21:29  deepslide-master\code\utils.py
     文件        9329  2019-07-15 21:29  deepslide-master\code\utils_evaluation.py
     文件       16941  2019-07-15 21:29  deepslide-master\code\utils_model.py
     文件       10735  2019-07-15 21:29  deepslide-master\code\utils_processing.py
     目录           0  2019-07-15 21:29  deepslide-master\code\z_preprocessing\
     文件         689  2019-07-15 21:29  deepslide-master\code\z_preprocessing\1_rename_files.py
     文件        3535  2019-07-15 21:29  deepslide-master\code\z_preprocessing\2_svs_to_jpg_tiles.py
     文件        3224  2019-07-15 21:29  deepslide-master\code\z_preprocessing\3_repiece_jpg_tiles.py
     文件        3896  2019-07-15 21:29  deepslide-master\code\z_preprocessing\4_anonymize.py
     文件        1029  2019-07-15 21:29  deepslide-master\code\z_preprocessing\compress.sh
     文件        2169  2019-07-15 21:29  deepslide-master\code\z_preprocessing\compress_images.py
     目录           0  2019-07-15 21:29  deepslide-master\figures\
     文件     1650211  2019-07-15 21:29  deepslide-master\figures\figure-2-color.jpeg
     文件     6800842  2019-07-15 21:29  deepslide-master\figures\sample.jpeg

评论

共有 条评论