File size: 2,229 Bytes
64ea7b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from aix import Dataset
import aix.constants as C
import os
import numpy as np
import cv2

def load_image(path):

    img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
    array = np.reshape(img, (img.shape[0], img.shape[1], -1)) / 255

    return array

def temp_numpy_masks(training_fold):

    image_rows = C.IMG_WIDTH
    image_cols = C.IMG_HEIGHT

    X_train = np.ndarray((len(training_fold[0]), image_rows, image_cols, 1), dtype = np.float64)
    y_train = np.ndarray((len(training_fold[1]), image_rows, image_cols, 1), dtype = np.float64)
    X_test = np.ndarray((len(training_fold[2]), image_rows, image_cols, 1), dtype = np.float64)
    y_test = np.ndarray((len(training_fold[3]), image_rows, image_cols, 1), dtype = np.float64)

    for i, obj in enumerate(training_fold[0]):

        img = load_image(obj)
        img = cv2.resize(img, (image_cols, image_rows), interpolation = cv2.INTER_AREA)
        img = np.expand_dims(img, axis = 2)
        X_train[i] = img

    for i, obj in enumerate(training_fold[1]):

        mask = load_image(obj)
        mask = cv2.resize(mask, (image_cols, image_rows), interpolation = cv2.INTER_AREA)
        mask = np.expand_dims(mask, axis = 2)
        y_train[i] = mask

    for i, obj in enumerate(training_fold[2]):

        img = load_image(obj)
        img = cv2.resize(img, (image_cols, image_rows), interpolation = cv2.INTER_AREA)
        img = np.expand_dims(img, axis = 2)
        X_test[i] = img

    for i, obj in enumerate(training_fold[3]):

        mask = load_image(obj)
        mask = cv2.resize(mask, (image_cols, image_rows), interpolation = cv2.INTER_AREA)
        mask = np.expand_dims(mask, axis = 2)
        y_test[i] = mask

    return X_train, y_train, X_test, y_test

def load_training_batch(name = 'average_model', oocytes_list = [], images_path = '', annotations_path = ''):

    dataset = Dataset(name, oocytes_list, images_path, annotations_path)

    gen = dataset.train_test_iterator()

    j = 0
    folds = []
    for x_train, x_test, y_train, y_test in gen:

        j += 1
        print(j)
        folds.append(temp_numpy_masks([x_train, y_train, x_test, y_test]))

        # save temporary numpies??

        # DO MODEL stuff in here

    return folds