-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCM_AC_runtraining.py
69 lines (52 loc) · 1.99 KB
/
CM_AC_runtraining.py
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
#%% Train the network per year
#for year in range(2007,2016):
import os
import numpy as np
import scipy.io as spio
from keras import backend as K
import platform
pl=platform.system()
if pl=='Linux':
os.chdir('/nethome/nilsolav/repos/github/COGMAR_ACOUSTIC')
os.environ["CUDA_VISIBLE_DEVICES"]="1"
else:
os.chdir('D:\\repos\\Github\\COGMAR_ACOUSTIC')
import CM_AC_models as md
#%% Get the model
K.clear_session()
freqs=4
model = md.model(freqs)
# File locations
if pl=='Linux':
#fld = '/data/deep/data/echosounder/akustikk_all/data/DataOverview_North Sea NOR Sandeel cruise in Apr_May/'
fld = '/scratch/nilsolav/deep/data/echosounder/akustikk_all/data/DataOverview_North Sea NOR Sandeel cruise in Apr_May/images/'
fld2 = '/scratch/nilsolav/deep/data/echosounder/akustikk_all/data/DataOverview_North Sea NOR Sandeel cruise in Apr_May/modelparameters/'
else:
fld = 'D:\\data\\deep\\echosounder\\akustikk_all\\data\DataOverview_North Sea NOR Sandeel cruise in Apr_May\\'
fld2 = 'D:\\data\\deep\\echosounder\\akustikk_all\\data\DataOverview_North Sea NOR Sandeel cruise in Apr_May\\'
# Do da shit
flds = os.listdir(fld)
#%% Run 20 epochs
for epochs in np.arange(50).astype('int'):
# Loop over batches
for file in flds:
if file.endswith(".npz"):
print('Epoch:'+str(epochs)+'; file: '+file)
try:
dat=np.load(fld+file)
batch_im = dat["imgs"]
batch_id = dat["speciesid"]
print(batch_id.shape)
print(batch_im.shape)
r = True
except:
print('Failed to load: '+file)
r = False
if r:
model.fit(batch_im,batch_id,verbose=0)
# Get the weights
dat=model.get_weights()
mod=model.to_json()
# Save the weights as numpy after each epoch
np.savez(fld2+'modelweights_epoch_'+str(epochs)+'.npz',dat=dat,mod=mod)
#%%