import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport osimport h5py as h5import torch as th
C:\Users\braun\AppData\Local\Temp\ipykernel_46816\3973438280.py:2: DeprecationWarning:
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466
import pandas as pd
# Create example input for tracingexample_input = data3dt[:1]model.eval()# Use torch.jit.trace to create a traced version of the modeltraced_model = th.jit.trace(model, example_input)# Replace the original model with the traced versionmodel = traced_modelfor epoch inrange(num_epochs): total_loss =0 num_batches =0# Iterate over batchesfor i inrange(0, len(data3dt), batch_size): batch = data3dt[i:i+batch_size]# Zero gradients optimizer.zero_grad()# Forward pass recon_batch, mu, log_var = model(batch)# Calculate loss loss = loss_function(recon_batch, batch, mu, log_var)# Backward pass loss.backward()# Update weights optimizer.step() total_loss += loss.item() num_batches +=1# Print progress avg_loss = total_loss / num_batchesprint(f'Epoch [{epoch+1}/{num_epochs}], Average Loss: {avg_loss:.4f}')
/home/philipp/mambaforge/envs/main11/lib/python3.11/site-packages/torch/jit/_trace.py:1116: TracerWarning: Trace had nondeterministic nodes. Did you forget call .eval() on your model? Nodes:
%eps : Float(1, 3, strides=[3, 1], requires_grad=0, device=cuda:0) = aten::randn_like(%std, %180, %181, %182, %183, %184) # /tmp/ipykernel_457356/3107499789.py:44:0
This may cause errors in trace checking. To disable trace checking, pass check_trace=False to torch.jit.trace()
_check_trace(
/home/philipp/mambaforge/envs/main11/lib/python3.11/site-packages/torch/jit/_trace.py:1116: TracerWarning: Output nr 1. of the traced function does not match the corresponding output of the Python function. Detailed error:
Tensor-likes are not close!
Mismatched elements: 16347 / 16384 (99.8%)
Greatest absolute difference: 0.04185950756072998 at index (0, 0, 39, 27) (up to 1e-05 allowed)
Greatest relative difference: 0.08788865663083263 at index (0, 0, 39, 27) (up to 1e-05 allowed)
_check_trace(
Epoch [1/3], Average Loss: 8489.5454
Epoch [2/3], Average Loss: 6916.7546
Epoch [3/3], Average Loss: 6891.0922