<jupyter_start><jupyter_text>- https://www.kaggle.com/c/data-science-bowl-2018/code?competitionId=8089&sortBy=voteCount- https://www.youtube.com/watch?v=RaswBvMnFxk&list=PLZsOBAyNTZwbR08R959iCvYT3qzhxvGOE&index=6- manche Bilder sind farbig, darauf geht Tut nicht ein. - Im Tut ist auch kein astype zu float für y gemacht, was eine Fehlermeldung bei der Bildanzeige gibt<jupyter_code>import os
import random
import numpy as np
 
from tqdm import tqdm 

from skimage.io import imread, imshow
from skimage.transform import resize
import matplotlib.pyplot as plt
TRAIN_PATH = r'E:/data/Projects/Semantic Segmentation/Malaria/stage1_train/'
TEST_PATH = r'E:/data/Projects/Semantic Segmentation/Malaria/stage1_test/'
IMG_WIDTH = 128
IMG_HEIGHT = 128
IMG_CHANNELS = 3
# os.walk gibt Tupel aus Ordnern aus, mit [1] nur das zweite aus dem Tupel, hier name von unterordner
# next gibt nächstes Element von Iterator zurück

train_ids = next(os.walk(TRAIN_PATH))[1]
test_ids = next(os.walk(TEST_PATH))[1]

# Pics resize
# macht leeres array und updated es dann mit den infos des bildes

X_train = np.zeros((len(train_ids), IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS), dtype=np.uint8)
Y_train = np.zeros((len(train_ids), IMG_HEIGHT, IMG_WIDTH, 1), dtype=bool)
print('Resizing training images and masks')
for n, id_ in tqdm(enumerate(train_ids), total=len(train_ids)):   
    path = TRAIN_PATH + id_
    img = imread(path + '/images/' + id_ + '.png')[:,:,:IMG_CHANNELS]  
    img = resize(img, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)
    X_train[n] = img  
    
    # Masken-Array füllen und alle Masken zu einer vereinen
    mask = np.zeros((IMG_HEIGHT, IMG_WIDTH, 1), dtype=bool)
    for mask_file in next(os.walk(path + '/masks/'))[2]:
        mask_ = imread(path + '/masks/' + mask_file)
        mask_ = np.expand_dims(resize(mask_, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True), axis=-1)
        mask = np.maximum(mask, mask_)  
            
    Y_train[n] = mask   
# ohne das hier hatte ich bei der Bildanzeige eine Fehlermeldung für die bools
Y_train = Y_train.astype('float')
# test images
X_test = np.zeros((len(test_ids), IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS), dtype=np.uint8)
sizes_test = []
print('Resizing test images') 
for n, id_ in tqdm(enumerate(test_ids), total=len(test_ids)):
    path = TEST_PATH + id_
    img = imread(path + '/images/' + id_ + '.png')[:,:,:IMG_CHANNELS]
    sizes_test.append([img.shape[0], img.shape[1]])
    img = resize(img, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)
    X_test[n] = img<jupyter_output>9%|███████▋                                                                           | 6/65 [00:00<00:01, 43.19it/s]<jupyter_text>https://stackoverflow.com/questions/34990652/why-do-we-need-np-squeeze/53213643<jupyter_code>image_x = random.randint(0, len(train_ids))
imshow(X_train[image_x])
plt.show()
imshow(np.squeeze(Y_train[image_x]))
plt.show()
from numpy import asarray
from numpy import save
save('X_train.npy', X_train)
save('X_test.npy', X_test)
save('Y_train.npy', Y_train)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13101000322684736, 'fraction_numerical': 0.021942562116811875, 'mean_word_length': 4.381944444444445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '193029', 'license': 'MIT', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1185, 'n_words': 256, 'path': '01_Images.ipynb', 'repo_name': 'daimonae/SemanticSegmentationNuclei', 'size': '3099'}