diff --git a/Bericht/Bilder/UNet_Architecture.svg b/Bericht/Bilder/UNet_Architecture.svg index ac8b625d553089da93f7771fdac40d659b39a491..7f8b38e6dbf7a4718a0caa2ebfff67cd66f6cb71 100644 --- a/Bericht/Bilder/UNet_Architecture.svg +++ b/Bericht/Bilder/UNet_Architecture.svg @@ -31,7 +31,7 @@ inkscape:stockid="TriangleOutL"> <path transform="scale(0.8)" - style="fill:#ffed00;fill-opacity:1;fill-rule:evenodd;stroke:#ffed00;stroke-width:1.00000003pt;stroke-opacity:1" + style="fill:#f6a800;fill-opacity:1;fill-rule:evenodd;stroke:#f6a800;stroke-width:1.00000003pt;stroke-opacity:1" d="M 5.77,0 -2.88,5 V -5 Z" id="path7971" inkscape:connector-curvature="0" /> @@ -213,7 +213,7 @@ inkscape:stockid="TriangleOutL"> <path transform="scale(0.8)" - style="fill:#ffed00;fill-opacity:1;fill-rule:evenodd;stroke:#ffed00;stroke-width:1.00000003pt;stroke-opacity:1" + style="fill:#f6a800;fill-opacity:1;fill-rule:evenodd;stroke:#f6a800;stroke-width:1.00000003pt;stroke-opacity:1" d="M 5.77,0 -2.88,5 V -5 Z" id="path7971-6" inkscape:connector-curvature="0" /> @@ -228,7 +228,7 @@ inkscape:stockid="TriangleOutL"> <path transform="scale(0.8)" - style="fill:#ffed00;fill-opacity:1;fill-rule:evenodd;stroke:#ffed00;stroke-width:1.00000003pt;stroke-opacity:1" + style="fill:#f6a800;fill-opacity:1;fill-rule:evenodd;stroke:#f6a800;stroke-width:1.00000003pt;stroke-opacity:1" d="M 5.77,0 -2.88,5 V -5 Z" id="path7971-6-5" inkscape:connector-curvature="0" /> @@ -310,7 +310,7 @@ inkscape:connector-curvature="0" id="path4668-4-8-6-1-40-1" d="M 5.77,0 -2.88,5 V -5 Z" - style="fill:#ffed00;fill-opacity:1;fill-rule:evenodd;stroke:#ffed00;stroke-width:1.00000003pt;stroke-opacity:1" + style="fill:#f6a800;fill-opacity:1;fill-rule:evenodd;stroke:#f6a800;stroke-width:1.00000003pt;stroke-opacity:1" transform="scale(0.8)" /> </marker> <marker @@ -529,7 +529,7 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="2" - inkscape:cx="421.03562" + inkscape:cx="336.03562" inkscape:cy="210.54105" inkscape:document-units="mm" inkscape:current-layer="layer1" @@ -557,7 +557,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -779,7 +779,7 @@ inkscape:connector-curvature="0" sodipodi:nodetypes="cc" /> <path - style="fill:none;stroke:#ffed00;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#TriangleOutL-1-6-9-5-9-4)" + style="fill:none;stroke:#f6a800;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#TriangleOutL-1-6-9-5-9-4)" d="m 30.162508,65.225008 13.75834,-5e-6" id="path4524-5-9-2-5-7-9" inkscape:connector-curvature="0" @@ -830,7 +830,7 @@ style="font-size:2.11666656px;fill:#e30066;fill-opacity:1;stroke-width:0.26458332">SeparableConv3D (1, 1, 1), sigmoids</tspan></text> <text xml:space="preserve" - style="font-style:normal;font-weight:normal;font-size:2.11666656px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffed00;fill-opacity:1;stroke:none;stroke-width:0.26458332" + style="font-style:normal;font-weight:normal;font-size:2.11666656px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#f6a800;fill-opacity:1;stroke:none;stroke-width:0.26458332;" x="45.772942" y="65.816185" id="text5568-6-11-8-8-27-5"><tspan @@ -838,7 +838,7 @@ id="tspan5566-1-5-3-9-5-9" x="45.772942" y="65.816185" - style="font-size:2.11666656px;fill:#ffed00;fill-opacity:1;stroke-width:0.26458332">Skip connection</tspan></text> + style="font-size:2.11666656px;fill:#f6a800;fill-opacity:1;stroke-width:0.26458332;">Skip connection</tspan></text> <text xml:space="preserve" style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332" @@ -967,13 +967,13 @@ style="font-size:64.99999762%;baseline-shift:super" id="tspan3635">3</tspan></tspan></text> <path - style="fill:none;stroke:#ffed00;stroke-width:0.2276167;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7973-0-2)" + style="fill:none;stroke:#f6a800;stroke-width:0.2276167;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7973-0-2)" d="M -78.052083,10.98541 H 40.521184" id="path7963-0-5" inkscape:connector-curvature="0" sodipodi:nodetypes="cc" /> <path - style="fill:none;stroke:#ffed00;stroke-width:0.23674184;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7973-0)" + style="fill:none;stroke:#f6a800;stroke-width:0.23674184;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7973-0)" d="M -56.577293,25.802087 H 14.602018" id="path7963-0" inkscape:connector-curvature="0" @@ -1107,7 +1107,7 @@ y="38.464565" style="font-size:2.11666656px;stroke-width:0.26458332">128</tspan></text> <path - style="fill:none;stroke:#ffed00;stroke-width:0.29850301;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7973)" + style="fill:none;stroke:#f6a800;stroke-width:0.29850301;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker7973)" d="m -35.866709,40.089585 h 24.754215" id="path7963" inkscape:connector-curvature="0" diff --git a/DAMASK_3/processing/post/process_results.py b/DAMASK_3/processing/post/process_results.py index 2c31862b7256176fff9db7aa2c5980d223010c08..91f9f9ab05c21228c197aa58ca87f8d6cab3e30c 100644 --- a/DAMASK_3/processing/post/process_results.py +++ b/DAMASK_3/processing/post/process_results.py @@ -108,7 +108,7 @@ def display_Data(config: dict): mesh = pv.wrap(mesh) #wrap it up for visualization name_array = mesh.array_names #get list of all active fields field_index = name_array.index(config['field']) # ermittele den Index des gewählten Feldes - if iter_vtk == 2: # position des des zweiten Increments im Ausgabebildschirm + if iter_vtk == 2: # position des zweiten Increments im Ausgabebildschirm plotter.subplot(0,1) elif iter_vtk == 3: plotter.subplot(1,0) diff --git a/Literatur/Korrekturen/Inga_1.pdf b/Literatur/Korrekturen/Inga_1.pdf index 9adc23867f5861b49b706dab82328f44592040fb..7b69059835614e281ca0c9115ea54b6d609f28b0 100644 Binary files a/Literatur/Korrekturen/Inga_1.pdf and b/Literatur/Korrekturen/Inga_1.pdf differ diff --git a/UNet/Auswertung_64.py b/UNet/Auswertung_64.py index d184793b5573738ed421cf4e5543cf81f493bd40..b10c8dbad5551351790da1d5b10fcd75609d40ea 100644 --- a/UNet/Auswertung_64.py +++ b/UNet/Auswertung_64.py @@ -3,9 +3,10 @@ import numpy as np import torch.nn as nn import UNet_V14 as UNet import copy +from torch.utils.data.dataloader import DataLoader def rescale(output, normalization): - output_rescale = output.reshape(output.shape[2],output.shape[3],output.shape[4]) + output_rescale = output.reshape(64,64,64) if normalization is not None: if normalization.shape[0] == 2: min_label, max_label = normalization @@ -15,6 +16,21 @@ def rescale(output, normalization): output_rescale += min_label return output_rescale +class DeviceDataLoader(): + """Wrap a dataloader to move data to a device""" + def __init__(self, dl, device): + self.dl = dl + self.device = device + + def __iter__(self): + """Yield a batch of data after moving it to device""" + for b in self.dl: + yield UNet.to_device(b, self.device) + + def __len__(self): + """Number of batches""" + return len(self.dl) + def dataset_evaluation( normalization, model, dataloader, threshold = 0.05): model.eval() mean_error = [] @@ -25,14 +41,11 @@ def dataset_evaluation( normalization, model, dataloader, threshold = 0.05): for batch in dataloader: input, output = batch - input = copy.copy(input) output = copy.copy(output) - input = torch.unsqueeze(input,0) output = torch.unsqueeze(output,0) prediction = model(input) - input = input.detach().numpy() prediction = prediction.cpu().detach().numpy() - output = output.detach().numpy() + output = output.detach().cpu().numpy().reshape(64,64,64) prediction = rescale(prediction, normalization) output = rescale(output, normalization) error = (abs(output - prediction)/output) @@ -51,22 +64,18 @@ def best_sample_id(result): return index_min -def predict_stress(image_id, normalization, model, dataset,grain_data, UNet, device,threshold = 0.15): - input, output = dataset[image_id] - grain,_ = grain_data[image_id] - grain = copy.deepcopy(grain) +def predict_stress(sample, normalization, model,threshold = 0.15): + model.eval() + print(sample.shape) + inpu, output = sample + prediction = model(inpu) + grain,_ = copy.deepcopy(sample) grain = torch.unsqueeze(grain,0) grain = grain.detach().numpy() - input = copy.deepcopy(input) output = copy.deepcopy(output) - input = torch.unsqueeze(input,0) output = torch.unsqueeze(output,0) - xb = UNet.to_device(input, device) - model.eval() - prediction = model(xb) - input = input.detach().numpy() - prediction = prediction.detach().numpy() - output = output.detach().numpy() + prediction = prediction.detach().cpu().numpy() + output = output.detach().cpu().numpy() prediction = rescale(prediction, normalization) output = rescale(output, normalization) error = (abs(output - prediction)/output) @@ -108,26 +117,29 @@ def export_vtk(error, grains, stress, label,path): if __name__ == '__main__': export_path = '/home/yk138599/Hiwi/damask3/UNet/output/result_14' - Training_data = torch.load(f'/home/yk138599/Hiwi/damask3/UNet/Trainingsdata/TD_norm_64_angles.pt') + #Training_data = torch.load(f'/home/yk138599/Hiwi/damask3/UNet/Trainingsdata/TD_norm_64_angles.pt') #Training_data = torch.load(f'/content/drive/MyDrive/Bachlorarbeit/Input/TD_norm_32_phase.pt') - normalization = np.load(f'/home/yk138599/Hiwi/damask3/UNet/Trainingsdata/Norm_min_max_64_angles.npy', allow_pickle=True) + print('loaded normalization') #normalization = np.load(f'/content/drive/MyDrive/Bachlorarbeit/Input/Norm_min_max_32_phase.npy', allow_pickle=True) - model = UNet.UNet() device = UNet.get_default_device() - model = UNet.to_device(model.double(), device) - dataloader = UNet.Create_Dataloader(f'/home/yk138599/Hiwi/damask3/UNet/Trainingsdata/TD_norm_64_angles.pt',batch_size=1) - dataloader = UNet.DeviceDataLoader(dataloader,device) - model.load_state_dict(torch.load(f'/home/yk138599/Hiwi/damask3/UNet/output/V14/Unet_dict_V14.pth',map_location=torch.device('cuda'))) - - result= dataset_evaluation( normalization = normalization, model = model, dataset = copy.copy(Training_data), threshold = 0.05) - print(f'\t mean error over whole set: {result[0].mean():.4}%') - print(f'\t max error average: {result[1].mean():.4}% and maximum {result[1].max():.4}%') - print(f'\t average correct percentile of voxels over whole set: {result[2].mean():.4}%') - print(f'\t average deviation per RVE over whole set: {result[3].mean():.4} Pa') - print(f'\t average deviation in percent per RVE over whole set: {result[4].mean()*100.:.4} %') - np.save('/home/yk138599/Hiwi/damask3/UNet/output/V14/evaluation',result) - sample_index = best_sample_id(result) - print(f'best sample is: {sample_index}') - error,grains,prediction,label= predict_stress(sample_index, normalization = normalization, model = model, device=device, dataset = Training_data,grain_data =Training_data,UNet=UNet, threshold=0.15) - export_vtk(error,grains,prediction,label,export_path) \ No newline at end of file + dataset = torch.load(f'/home/yk138599/Hiwi/damask3/UNet/Trainingsdata/TD_norm_64_angles.pt') + dataloader = DataLoader(dataset,1, num_workers=1, pin_memory=True) + dataloader =DeviceDataLoader(dataloader,device) + model = UNet.to_device(UNet.UNet(kernel_size=9,normalization=normalization).double(), device) + model.load_state_dict(torch.load('/home/yk138599/Hiwi/damask3/UNet/output/Unet_dict_V14.pth')) + #model=UNet.to_device(UNet.UNet().load_state_dict(torch.load('/home/yk138599/Hiwi/damask3/UNet/output/Unet_dict_V14.pth')),device) + print('loaded Unet') + #result= dataset_evaluation( normalization = normalization, model = model,dataloader=dataloader, threshold = 0.05) + #np.save('/home/yk138599/Hiwi/damask3/UNet/output/V14/evaluation',result) + #print(f'\t mean error over whole set: {np.mean(result[0]):.4}%') + #print(f'\t max error average: {np.mean(result[1]):.4}% and maximum {np.max(result[1]):.4}%') + #print(f'\t average correct percentile of voxels over whole set: {np.mean(result[2]):.4}%') + #print(f'\t average deviation per RVE over whole set: {np.mean(result[3]):.4} Pa') + #print(f'\t average deviation in percent per RVE over whole set: {np.mean(result[4])*100.:.4} %') + + #sample_index = best_sample_id(result) + sample_index = 144 + sample = UNet.to_device(copy.copy(dataset[sample_index]), device) + error,grains,prediction,label= predict_stress( sample, normalization = normalization, model = model, device=device,UNet=UNet, threshold=0.15) + export_vtk(error,grains,prediction,label,export_path)