Skip to content
Snippets Groups Projects
Commit 260058fc authored by Brian Christopher Wasels's avatar Brian Christopher Wasels
Browse files

Merge branch 'master' of git-ce.rwth-aachen.de:wasels.chr/damask3

merge cluster work
parents 04af532c c4e18fe5
Branches
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
This diff is collapsed.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
%% Cell type:code id: tags:
``` python
import torch
import numpy as np
import torch.nn as nn
from torch.utils.data import TensorDataset
import sklearn.preprocessing as sp
```
%% Cell type:code id: tags:
``` python
min_label, max_label,angles_min_max = np.load('E:/Data/damask3/UNet/Input/Norm_min_max_64.npy', allow_pickle= True)
```
%% Cell type:code id: tags:
``` python
training_data = np.load('E:/Data/damask3/UNet/Input/Training_data_64.npy')
training_label = np.load('E:/Data/damask3/UNet/Input/Training_labels_64.npy')
training_data = training_data[0:50]
training_label = training_label[0:50]
if training_data.shape[0] != training_label.shape[0]:
print('label and data have not the same size')
#Desired input shape: (N,C,D,H,W) N=Batchsize, C=Channel, D=Depth, H=Height, W = Width
data = np.moveaxis(training_data,4,1) # GAN output has shape(N,W,H,D,C) but no need to change spatial dimensions, but Channel dimension must be changed
#input[0-3]: Orientation, input[4]: Phase(one for martinsite)
```
%% Cell type:code id: tags:
``` python
angles = data[:,0:4,...]
angles_min_max= np.zeros((2,angles.shape[1]))
for i in range(angles.shape[1]):
s_batch,_,width, height, depth = angles.shape
column= angles[:,i,...]
angles_min_max[0,i] = column.min()
angles_min_max[1,i] = column.max()
column -= angles_min_max[0,i]
column /= angles_min_max[1,i]
column = column.reshape(s_batch,width, height, depth)
angles[:,i,...] = column
```
%% Cell type:code id: tags:
``` python
#training_label = training_label[:,np.newaxis,...]
phase= data[:,4,:,:,:].reshape(data.shape[0], 1,64,64,64)
new_phase = np.ones(phase.shape) - phase #input[4]: martinsite, input[5]:ferrit
#new_training_data = np.append(data,new_channel,axis=1)
input = np.append(angles,phase,axis=1)
input = np.append(input,new_phase,axis=1)
#input = np.append(angles,phase,axis=1)
#input = np.append(input,new_phase,axis=1)
input = np.append(phase,new_phase,axis=1)
label = torch.from_numpy(training_label)
input = torch.from_numpy(input)
if label.dtype != torch.float64:
label = label.double()
if input.dtype != torch.float64:
input = input.double()
#angles = torch.from_numpy(angles)
print(f'size of input is {input.size()}')
print(f'size of label is {label.size()}')
```
%% Output
size of input is torch.Size([791, 6, 64, 64, 64])
size of label is torch.Size([791, 64, 64, 64])
size of input is torch.Size([50, 2, 64, 64, 64])
size of label is torch.Size([50, 64, 64, 64])
%% Cell type:code id: tags:
``` python
label_normalized = label.view(label.size(0), -1)
min_label = label_normalized.min().numpy()
max_label = label_normalized.max().numpy()
s_batch, width, height, depth = label.size()
label_normalized -= min_label
label_normalized /= max_label
label_normalized = label_normalized.view(s_batch, width, height, depth)
label_normalized = label_normalized[:,np.newaxis,...]
```
%% Cell type:code id: tags:
``` python
dataset = TensorDataset(input,label_normalized) # create the pytorch dataset
np.save('E:/Data/damask3/UNet/Input/Norm_min_max_64_angles.npy',[min_label, max_label])
torch.save(dataset,'E:/Data/damask3/UNet/Input/TD_norm_64_angles.pt')
np.save('E:/Data/damask3/UNet/Input/Norm_min_max_64_subset_phase.npy',[min_label, max_label])
torch.save(dataset,'E:/Data/damask3/UNet/Input/TD_norm_64_subset_phase.pt')
```
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment