AltumAge#
Index#
Let’s first import some packages:
[1]:
import os
import inspect
import shutil
import json
import torch
import pandas as pd
import pyaging as pya
import tensorflow as tf
from tensorflow.keras.models import load_model
Instantiate model class#
[2]:
def print_entire_class(cls):
source = inspect.getsource(cls)
print(source)
print_entire_class(pya.models.AltumAge)
class AltumAge(pyagingModel):
def __init__(self):
super().__init__()
def preprocess(self, x):
"""
Scales an array based on the median and standard deviation.
"""
median = torch.tensor(
self.preprocess_dependencies[0], device=x.device, dtype=x.dtype
)
std = torch.tensor(
self.preprocess_dependencies[1], device=x.device, dtype=x.dtype
)
x = (x - median) / std
return x
def postprocess(self, x):
return x
[3]:
model = pya.models.AltumAge()
Define clock metadata#
[4]:
model.metadata["clock_name"] = 'altumage'
model.metadata["data_type"] = 'methylation'
model.metadata["species"] = 'Homo sapiens'
model.metadata["year"] = 2022
model.metadata["approved_by_author"] = '✅'
model.metadata["citation"] = "de Lima Camillo, Lucas Paulo, Louis R. Lapierre, and Ritambhara Singh. \"A pan-tissue DNA-methylation epigenetic clock based on deep learning.\" npj Aging 8.1 (2022): 4."
model.metadata["doi"] = 'https://doi.org/10.1038/s41514-022-00085-y'
model.metadata["research_only"] = None
model.metadata["notes"] = None
Download clock dependencies#
Download GitHub repository#
[5]:
github_url = "https://github.com/rsinghlab/AltumAge.git"
github_folder_name = github_url.split('/')[-1].split('.')[0]
os.system(f"git clone {github_url}")
[5]:
0
Load features#
[6]:
model.features = pd.read_pickle('AltumAge/example_dependencies/multi_platform_cpgs.pkl').tolist()
Load weights into base model#
[7]:
AltumAge = load_model('AltumAge/example_dependencies/AltumAge.h5') # Load your trained TensorFlow model
weights = {}
for layer in AltumAge.layers:
weights[layer.name] = layer.get_weights()
base_model = pya.models.AltumAgeNeuralNetwork()
# Function to copy weights from TensorFlow to PyTorch
def copy_weights(torch_layer, tf_weights, bn=False):
with torch.no_grad():
if bn:
torch_layer.weight.data = torch.tensor(tf_weights[0]).float()
torch_layer.bias.data = torch.tensor(tf_weights[1]).float()
torch_layer.running_mean.data = torch.tensor(tf_weights[2]).float()
torch_layer.running_var.data = torch.tensor(tf_weights[3]).float()
else:
torch_layer.weight.data = torch.tensor(tf_weights[0]).T.float()
torch_layer.bias.data = torch.tensor(tf_weights[1]).float()
# Now copy the weights
copy_weights(base_model.bn1, weights['batch_normalization_84'], bn=True)
copy_weights(base_model.linear1, weights['dense_84'])
copy_weights(base_model.bn2, weights['batch_normalization_85'], bn=True)
copy_weights(base_model.linear2, weights['dense_85'])
copy_weights(base_model.bn3, weights['batch_normalization_86'], bn=True)
copy_weights(base_model.linear3, weights['dense_86'])
copy_weights(base_model.bn4, weights['batch_normalization_87'], bn=True)
copy_weights(base_model.linear4, weights['dense_87'])
copy_weights(base_model.bn5, weights['batch_normalization_88'], bn=True)
copy_weights(base_model.linear5, weights['dense_88'])
copy_weights(base_model.bn6, weights['batch_normalization_89'], bn=True)
copy_weights(base_model.linear6, weights['dense_89'])
model.base_model = base_model
Load reference values#
[8]:
scaler = pd.read_pickle('AltumAge/example_dependencies/scaler.pkl')
model.reference_values = scaler.center_
Load preprocess and postprocess objects#
[9]:
model.preprocess_name = 'scale'
model.preprocess_dependencies = [scaler.center_, scaler.scale_]
[10]:
model.postprocess_name = None
model.postprocess_dependencies = None
Check all clock parameters#
[11]:
pya.utils.print_model_details(model)
%==================================== Model Details ====================================%
Model Attributes:
training: True
metadata: {'approved_by_author': '✅',
'citation': 'de Lima Camillo, Lucas Paulo, Louis R. Lapierre, and Ritambhara '
'Singh. "A pan-tissue DNA-methylation epigenetic clock based on '
'deep learning." npj Aging 8.1 (2022): 4.',
'clock_name': 'altumage',
'data_type': 'methylation',
'doi': 'https://doi.org/10.1038/s41514-022-00085-y',
'notes': None,
'research_only': None,
'species': 'Homo sapiens',
'version': None,
'year': 2022}
reference_values: array([0.7598634 , 0.78637881, 0.06324422, ..., 0.03556449, 0.04053195,
0.05189659])
preprocess_name: 'scale'
preprocess_dependencies: [array([0.7598634 , 0.78637881, 0.06324422, ..., 0.03556449, 0.04053195,
0.05189659]),
array([0.18540869, 0.42506826, 0.03971112, ..., 0.0264798 , 0.01924175,
0.03057686])]
postprocess_name: None
postprocess_dependencies: None
features: ['cg00000292', 'cg00002426', 'cg00003994', 'cg00007981', 'cg00008493', 'cg00008713', 'cg00009407', 'cg00011459', 'cg00012199', 'cg00012386', 'cg00013618', 'cg00014085', 'cg00014837', 'cg00015770', 'cg00021527', 'cg00022866', 'cg00024396', 'cg00024812', 'cg00025991', 'cg00027083', 'cg00027674', 'cg00029826', 'cg00031162', 'cg00032227', 'cg00033773', 'cg00034039', 'cg00035347', 'cg00035623', 'cg00037763', 'cg00037940']... [Total elements: 20318]
base_model_features: None
%==================================== Model Details ====================================%
Model Structure:
base_model: AltumAgeNeuralNetwork(
(linear1): Linear(in_features=20318, out_features=32, bias=True)
(linear2): Linear(in_features=32, out_features=32, bias=True)
(linear3): Linear(in_features=32, out_features=32, bias=True)
(linear4): Linear(in_features=32, out_features=32, bias=True)
(linear5): Linear(in_features=32, out_features=32, bias=True)
(linear6): Linear(in_features=32, out_features=1, bias=True)
(bn1): BatchNorm1d(20318, eps=0.001, momentum=0.99, affine=True, track_running_stats=True)
(bn2): BatchNorm1d(32, eps=0.001, momentum=0.99, affine=True, track_running_stats=True)
(bn3): BatchNorm1d(32, eps=0.001, momentum=0.99, affine=True, track_running_stats=True)
(bn4): BatchNorm1d(32, eps=0.001, momentum=0.99, affine=True, track_running_stats=True)
(bn5): BatchNorm1d(32, eps=0.001, momentum=0.99, affine=True, track_running_stats=True)
(bn6): BatchNorm1d(32, eps=0.001, momentum=0.99, affine=True, track_running_stats=True)
)
%==================================== Model Details ====================================%
Model Parameters and Weights:
base_model.linear1.weight: [1.246529063791968e-05, -0.0002471897751092911, 0.05430829897522926, -0.008294563740491867, -1.8199836631538346e-05, -0.0015183936338871717, 7.312353409361094e-05, -0.007021772209554911, 0.0005710566765628755, -0.006980041973292828, -0.0007858948083594441, -0.05727043002843857, -2.0795012460439466e-05, 0.0031408595386892557, -1.4749221918464173e-05, 0.01787472702562809, -5.4394153266912326e-05, 4.666849520162941e-07, -4.0518450987292454e-05, 0.0009429929195903242, -0.0001615934306755662, -0.0003702835529111326, -0.0012796352384611964, 4.2240975744789466e-05, 0.0002652845287229866, -0.00011791101132985204, 0.0038070667069405317, 0.0002058065147139132, 1.0669058610801585e-05, -0.01897735521197319]... [Tensor of shape torch.Size([32, 20318])]
base_model.linear1.bias: [-0.6604351997375488, 0.553255021572113, -0.2199789136648178, -0.17349956929683685, -0.5755764842033386, -0.5770981311798096, -0.85679030418396, -0.11386192589998245, -0.3227541446685791, -0.6420730352401733, -0.37273240089416504, -0.18069732189178467, -0.5826432108879089, -0.4565253257751465, -0.870608925819397, -0.45575329661369324, -0.4027813971042633, -0.6451340913772583, -0.5051977634429932, -0.425929993391037, -0.27907705307006836, -0.3261556029319763, -0.03588723763823509, -0.2229115515947342, -0.3301258981227875, -1.2168819904327393, -0.4373774826526642, -0.7384440898895264, -0.1962476670742035, -0.582466185092926]... [Tensor of shape torch.Size([32])]
base_model.linear2.weight: [-0.01094431709498167, -0.04170822724699974, -0.05536497011780739, -0.09377466142177582, -0.03199092671275139, 0.00929625891149044, -0.18309614062309265, -0.20925647020339966, 0.07220331579446793, -0.28390467166900635, 0.014310872182250023, 0.06769445538520813, 0.052944835275411606, -0.29175370931625366, 0.057607896625995636, 0.08242862671613693, 0.025601543486118317, -0.06525243818759918, -0.11426667869091034, 0.09226357936859131, -0.16103969514369965, 0.06995867937803268, 0.028462877497076988, 0.039109524339437485, -0.06065845116972923, 0.05917220562696457, -0.042923666536808014, -0.015095407143235207, 0.14895962178707123, 0.17299231886863708]... [Tensor of shape torch.Size([32, 32])]
base_model.linear2.bias: [0.6759097576141357, -0.30965256690979004, -0.435714453458786, 0.5533908009529114, 0.4850878119468689, 0.6324586868286133, 0.40164119005203247, 0.07538066804409027, -0.14314351975917816, 0.22218534350395203, -0.9658768177032471, 0.028701048344373703, 0.2947874963283539, 0.1958579421043396, 0.289803683757782, -0.6178198456764221, 0.36299121379852295, 0.2220699042081833, 0.19975309073925018, 0.47710251808166504, 0.2868340313434601, 0.5243813991546631, 0.13998520374298096, 0.6783063411712646, 0.3396126627922058, 0.35712605714797974, 0.05355028435587883, 0.15100054442882538, 0.29933637380599976, 0.4200878143310547]... [Tensor of shape torch.Size([32])]
base_model.linear3.weight: [-0.021995071321725845, -0.02987273968756199, -0.15411193668842316, -0.016349993646144867, -0.04685691371560097, -0.04662327468395233, -0.02454778552055359, -0.0840604305267334, 0.03940239176154137, -0.11689302325248718, -0.11210999637842178, 0.17825011909008026, 0.010129106231033802, -0.13402962684631348, 0.15750113129615784, 0.11931846290826797, 0.17011916637420654, -0.05783533304929733, -0.04352954775094986, 0.10090377926826477, -0.053706035017967224, -0.061015259474515915, 0.057148732244968414, 0.10137058049440384, -0.05920616164803505, 0.08705950528383255, 0.037306610494852066, 0.04856671392917633, 0.1369452178478241, 0.024091394618153572]... [Tensor of shape torch.Size([32, 32])]
base_model.linear3.bias: [0.3390987813472748, 0.5597915053367615, 0.4704841077327728, -0.2027052342891693, 0.18131421506404877, 0.3251790702342987, 0.023268038406968117, -0.3202570974826813, -0.08522506803274155, -0.09981230646371841, 0.6882339119911194, -0.16630201041698456, 0.1853657364845276, -0.13264507055282593, 0.37152430415153503, -0.002184227341786027, 0.4331909120082855, 0.4346664249897003, 0.15995217859745026, 0.3535030484199524, 0.12664175033569336, 0.271379292011261, 0.35560089349746704, 0.4138280153274536, -0.12752798199653625, 0.2425791472196579, 0.3175293207168579, -0.04349420592188835, 0.0036551435478031635, 0.3100642263889313]... [Tensor of shape torch.Size([32])]
base_model.linear4.weight: [0.06676768511533737, 0.08237684518098831, -0.00191324925981462, -0.13973116874694824, 0.06245503947138786, 0.04992462694644928, 0.06745247542858124, -0.1698061227798462, -0.048235226422548294, -0.0618303157389164, -0.1305021047592163, -0.08013364672660828, 0.10724075138568878, -0.08860236406326294, -0.06346510350704193, 0.06030706688761711, 0.1586315780878067, 0.053909145295619965, -0.07301212102174759, 0.13819999992847443, -0.05009153485298157, 0.1852218061685562, 0.09616599231958389, 0.1515057533979416, -0.14782537519931793, 0.031154176220297813, 0.02012978121638298, -0.04610324651002884, 0.030594587326049805, 0.007588792592287064]... [Tensor of shape torch.Size([32, 32])]
base_model.linear4.bias: [0.4490607678890228, 0.18022336065769196, -0.4009992480278015, 0.5019789338111877, -0.19787806272506714, -0.5556692481040955, -0.36530664563179016, 0.9969112873077393, 0.1408386528491974, 0.2968444526195526, 0.1477593034505844, 0.5978249907493591, -0.21193064749240875, 0.042447708547115326, 0.4133152365684509, -0.5278348922729492, -0.3183741867542267, 0.04163779318332672, -0.5462782979011536, 0.22142723202705383, -0.3050590753555298, -0.635915994644165, 0.13981595635414124, 0.31476834416389465, 0.20478305220603943, 0.44763973355293274, -0.8668853044509888, -0.1751948893070221, 0.655350387096405, -0.06569192558526993]... [Tensor of shape torch.Size([32])]
base_model.linear5.weight: [0.0184211153537035, -0.05929525941610336, 0.05623525381088257, -0.13201911747455597, -0.3709865212440491, -0.0021386153530329466, -0.3606453239917755, -0.2683887183666229, -0.05518096312880516, -0.19705729186534882, -0.2192695140838623, 0.005195553880184889, -0.28843310475349426, -0.3016926050186157, 0.07239656150341034, 0.20863215625286102, 0.15509693324565887, 0.010939259082078934, -0.08767764270305634, 0.047880880534648895, -0.45227083563804626, 0.027277885004878044, -0.05277041718363762, 0.07155202329158783, -0.02678997814655304, 0.037785377353429794, 0.0011355951428413391, 0.13122519850730896, 0.12031804770231247, 0.04317126423120499]... [Tensor of shape torch.Size([32, 32])]
base_model.linear5.bias: [0.01876211352646351, 1.0648096799850464, 0.5158078074455261, 0.11877239495515823, 0.2151409536600113, 0.45924338698387146, 0.6236221194267273, 0.41232115030288696, 0.22964538633823395, 0.4292854964733124, 0.5148159861564636, 0.49106964468955994, 0.7502755522727966, 0.31809237599372864, 0.6128279566764832, 0.055782247334718704, 0.5655565857887268, 0.6442739963531494, 0.4925069808959961, 0.14436039328575134, 0.9095592498779297, 0.014249259606003761, 0.16974158585071564, -0.09505554288625717, -0.12489812821149826, 0.5696980953216553, 0.5375333428382874, -0.3432300090789795, 0.1093614473938942, 0.930426299571991]... [Tensor of shape torch.Size([32])]
base_model.linear6.weight: [-1.2235809564590454, 1.280374526977539, 1.0837292671203613, -0.9721303582191467, -1.1045821905136108, 1.1073765754699707, 1.281290054321289, -1.022849440574646, 1.1068447828292847, 1.0666595697402954, 1.0868101119995117, 1.0926932096481323, 1.2181103229522705, 1.116851806640625, 0.9926596283912659, -1.3032453060150146, -1.0006746053695679, -1.1439409255981445, 1.2465311288833618, 1.2645983695983887, 1.1992582082748413, -1.2771034240722656, -1.282519817352295, -1.1069782972335815, -1.1649847030639648, 1.2752622365951538, -0.9725183248519897, -1.1401984691619873, 1.093029260635376, 1.0757770538330078]... [Tensor of shape torch.Size([1, 32])]
base_model.linear6.bias: tensor([0.7534])
base_model.bn1.weight: [-2.277722887811251e-05, 0.0002871362376026809, 0.1023154929280281, 0.040351882576942444, 1.0724440926423995e-06, 0.0004446406674105674, 4.4160471588838845e-05, 0.05098670348525047, -0.0020682530011981726, 0.00508534163236618, 6.948724330868572e-05, 0.039365433156490326, 2.3533266357844695e-06, 0.017978468909859657, 0.00016859255265444517, 0.09126225858926773, -1.9927823814214207e-05, -0.00026886435807682574, -0.0001723309833323583, 0.05571595951914787, 4.985986015526578e-05, 4.162726327194832e-05, 0.034322887659072876, 2.3904536647023633e-05, -3.214006937923841e-05, 9.075140405911952e-05, 0.00466049974784255, -0.00021367349836509675, -0.00029762519989162683, 0.05293723940849304]... [Tensor of shape torch.Size([20318])]
base_model.bn1.bias: [-0.00014154697419144213, -0.00019684169092215598, 0.02398889884352684, 0.005562401842325926, -6.7388978095550556e-06, -0.0004771985695697367, -0.0002616412239149213, -0.0033491128124296665, 0.002524091862142086, 0.0017261839238926768, 0.0003650723083410412, 0.0330529548227787, 4.6587319957325235e-05, 0.01295486930757761, 0.0002475477522239089, 0.006131553091108799, -0.00037227830034680665, 0.00012894070823676884, 6.310200842563063e-05, 0.011103571392595768, 0.0005883763078600168, -0.0001323629985563457, -0.0016743054147809744, -0.00010214522626483813, -0.000319397309795022, -0.00014953040226828307, 0.0006810991326346993, 0.00037444932968355715, 0.00022694426297675818, -0.02956547401845455]... [Tensor of shape torch.Size([20318])]
base_model.bn2.weight: [0.6905478239059448, 0.8970890045166016, 0.9815526008605957, 0.9541947245597839, 0.6961821913719177, 0.6562688946723938, 1.021709680557251, 0.686607837677002, 1.079068899154663, 1.2397785186767578, 0.8452786803245544, 0.896165668964386, 0.7615985870361328, 1.0136444568634033, 1.0088087320327759, 0.26919686794281006, 0.8767375349998474, 0.548994243144989, 1.1166812181472778, 0.7769761085510254, 0.8877885937690735, 0.8992270827293396, 0.9020530581474304, 0.9531307220458984, 1.0407384634017944, 0.9544910788536072, 0.6271775364875793, 0.6259847283363342, 1.0941461324691772, 1.2867493629455566]... [Tensor of shape torch.Size([32])]
base_model.bn2.bias: [0.04435224458575249, -0.21411113440990448, 0.4301947057247162, 0.2861901819705963, 0.11047084629535675, 0.2937158942222595, 0.3426212668418884, 0.0001008358522085473, 0.06101381406188011, 0.3651764690876007, -0.18807388842105865, 0.10774523764848709, 0.09403035789728165, 0.3090708553791046, -0.03353693708777428, 0.1653040051460266, 0.40594643354415894, 0.22363099455833435, 0.49713653326034546, 0.030241988599300385, 0.3876751661300659, 0.3290156424045563, -0.04752155765891075, 0.3579997718334198, 0.32806387543678284, 0.02159624733030796, 0.01705360971391201, 0.25464296340942383, 0.09353916347026825, 0.01985369808971882]... [Tensor of shape torch.Size([32])]
base_model.bn3.weight: [0.9234421849250793, 0.7930188775062561, 0.7817761301994324, 0.9887698292732239, 0.896285891532898, 0.8971582651138306, 0.9323441386222839, 0.9249641299247742, 0.9125398993492126, 0.8330692052841187, 0.939758837223053, 0.8861827254295349, 0.99076908826828, 0.8512395620346069, 0.8914241790771484, 0.7827310562133789, 0.7608182430267334, 0.8271699547767639, 0.9560512900352478, 0.7843223214149475, 0.9761922955513, 0.8006914854049683, 0.9329655170440674, 1.222071886062622, 0.847257137298584, 0.7802505493164062, 0.9128558039665222, 0.9528391361236572, 0.8709290027618408, 0.9304196238517761]... [Tensor of shape torch.Size([32])]
base_model.bn3.bias: [-0.19250787794589996, 0.14874595403671265, 0.1638125330209732, 0.3546788990497589, 0.404529869556427, 0.36265066266059875, 0.26306986808776855, 0.2580764591693878, -0.0717070996761322, -0.04698715731501579, 0.10578188300132751, -0.029322730377316475, -0.23589958250522614, 0.18914519250392914, -0.14600355923175812, -0.004255604464560747, -0.1084597110748291, 0.24887894093990326, 0.23652781546115875, -0.20105773210525513, 0.04746703803539276, 0.3456309139728546, 0.3095207214355469, 0.2699720859527588, 0.17736199498176575, -0.20449143648147583, 0.27376991510391235, 0.20387518405914307, -0.23552724719047546, -0.1448889672756195]... [Tensor of shape torch.Size([32])]
base_model.bn4.weight: [0.8329624533653259, 1.1532669067382812, 1.0695139169692993, 1.2459280490875244, 1.4692071676254272, 0.8691132068634033, 1.067549228668213, 1.2267886400222778, 0.9916320443153381, 1.0002427101135254, 1.138911247253418, 1.0186805725097656, 0.8647685050964355, 1.3782200813293457, 1.0665796995162964, 0.9494524002075195, 0.8646358847618103, 1.0004198551177979, 1.2889724969863892, 0.8156601190567017, 0.9825426936149597, 1.2889742851257324, 0.9709151983261108, 0.9443548321723938, 1.0750848054885864, 0.8902947902679443, 1.1574288606643677, 0.8986280560493469, 0.921513020992279, 1.0052399635314941]... [Tensor of shape torch.Size([32])]
base_model.bn4.bias: [-0.37905755639076233, 0.23213420808315277, -0.3198325037956238, -0.2166614681482315, -0.18546313047409058, -0.2417532354593277, 0.19495508074760437, -0.10894335806369781, 0.5836881399154663, 0.06080053374171257, -0.0547979511320591, -0.24499523639678955, -0.3125092089176178, -0.10615140944719315, 0.4150526225566864, 0.1056458055973053, -0.42118528485298157, -0.061542510986328125, -0.06876606494188309, -0.24862727522850037, 0.2871303856372833, 0.4920126795768738, -0.16811516880989075, -0.3929504454135895, 0.03316299244761467, -0.26179489493370056, 0.3612964153289795, -0.2771378755569458, -0.3564463257789612, -0.16278406977653503]... [Tensor of shape torch.Size([32])]
base_model.bn5.weight: [0.5315274000167847, 0.7656521797180176, 0.9901968836784363, 0.7130084037780762, 0.7900282740592957, 0.8157933950424194, 0.9314822554588318, 0.9711773991584778, 0.8442395925521851, 0.7378012537956238, 0.9490993618965149, 0.7065261602401733, 0.7682647705078125, 0.6585373282432556, 0.6434342265129089, 0.8950735926628113, 0.9197940826416016, 0.7506937384605408, 0.9247902035713196, 0.6710596680641174, 0.8226577639579773, 1.0551987886428833, 0.617047905921936, 0.5817351937294006, 0.9910615086555481, 0.8779973983764648, 1.0696682929992676, 0.9234750866889954, 0.5643420815467834, 0.6997614502906799]... [Tensor of shape torch.Size([32])]
base_model.bn5.bias: [-0.23922225832939148, 0.05060812458395958, 0.0880344808101654, 0.349170446395874, 0.35085517168045044, 0.5096186995506287, 0.36524733901023865, 0.06328605115413666, 0.3355914354324341, 0.07497643679380417, 0.06132904067635536, 0.3036796748638153, 0.31382477283477783, 0.23931445181369781, -0.31519773602485657, 0.4774809777736664, 0.30365583300590515, 0.30634909868240356, 0.4935772120952606, 0.0023431822191923857, 0.3013705313205719, 0.5785077214241028, 0.18645833432674408, 0.20355689525604248, 0.006280350498855114, -0.11043797433376312, 0.4811197519302368, 0.3498353064060211, -0.2789755165576935, 0.2614656090736389]... [Tensor of shape torch.Size([32])]
base_model.bn6.weight: [1.3481643199920654, 1.4607722759246826, 1.4242678880691528, 1.231069564819336, 1.3522446155548096, 1.4518276453018188, 1.3152239322662354, 1.3747893571853638, 1.419804334640503, 1.4228943586349487, 1.4471609592437744, 1.4868443012237549, 1.3118786811828613, 1.4188650846481323, 1.4074370861053467, 1.3292601108551025, 1.2542840242385864, 1.32634437084198, 1.362012505531311, 1.394670009613037, 1.4886820316314697, 1.3188791275024414, 1.3590495586395264, 1.365369200706482, 1.373213529586792, 1.365676760673523, 1.2495394945144653, 1.2946306467056274, 1.4208099842071533, 1.50507390499115]... [Tensor of shape torch.Size([32])]
base_model.bn6.bias: [-1.0322566032409668, 0.9969916939735413, 1.1465765237808228, -1.2036560773849487, -1.0851515531539917, 1.1470754146575928, 0.9764208197593689, -1.2042585611343384, 1.143728256225586, 1.1630021333694458, 1.1460325717926025, 1.1626311540603638, 1.0003620386123657, 1.152819275856018, 1.2943443059921265, -0.9768348336219788, -1.2946065664291382, -1.0891062021255493, 1.0059713125228882, 1.0011463165283203, 1.0434279441833496, -0.9889340400695801, -0.9905285239219666, -1.1143995523452759, -1.072808027267456, 1.0112223625183105, -1.3086520433425903, -1.1203855276107788, 1.1454522609710693, 1.2001315355300903]... [Tensor of shape torch.Size([32])]
%==================================== Model Details ====================================%
Basic test#
[12]:
torch.manual_seed(42)
input = torch.randn(10, len(model.features), dtype=float)
model.eval()
model.to(float)
pred = model(input)
pred
[12]:
tensor([[ 1.6940e+01],
[-7.8034e-02],
[ 1.2900e+02],
[ 3.2433e+01],
[ 8.1607e+01],
[ 3.2819e+01],
[ 7.1175e+01],
[ 4.5454e+01],
[ 3.1396e+01],
[ 1.9619e+02]], dtype=torch.float64, grad_fn=<AddmmBackward0>)
Save torch model#
[13]:
torch.save(model, f"../weights/{model.metadata['clock_name']}.pt")
Clear directory#
[14]:
# Function to remove a folder and all its contents
def remove_folder(path):
try:
shutil.rmtree(path)
print(f"Deleted folder: {path}")
except Exception as e:
print(f"Error deleting folder {path}: {e}")
# Get a list of all files and folders in the current directory
all_items = os.listdir('.')
# Loop through the items
for item in all_items:
# Check if it's a file and does not end with .ipynb
if os.path.isfile(item) and not item.endswith('.ipynb'):
os.remove(item)
print(f"Deleted file: {item}")
# Check if it's a folder
elif os.path.isdir(item):
remove_folder(item)
Deleted folder: AltumAge
Deleted folder: .ipynb_checkpoints