Skip to content

Commit 35e070d

Browse files
dataangelOceania2018
authored andcommitted
Update hdf5_format.cs
1 parent 536b534 commit 35e070d

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/TensorFlowNET.Keras/Saving/hdf5_format.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Text;
44
using HDF.PInvoke;
@@ -136,11 +136,7 @@ public static void load_weights_from_hdf5_group(long f, List<ILayer> layers)
136136
var get_Name = "";
137137
foreach (var i_ in weight_names)
138138
{
139-
get_Name = i_;
140-
if (get_Name.IndexOf("/") > 1) {
141-
get_Name = get_Name.Split('/')[1];
142-
}
143-
(bool success, Array result) = Hdf5.ReadDataset<float>(g, get_Name, alternativeName: i_);
139+
(bool success, Array result) = Hdf5.ReadDataset<float>(g, i_);
144140
if (success)
145141
weight_values.Add(np.array(result));
146142
}
@@ -193,17 +189,19 @@ public static void save_weights_to_hdf5_group(long f, List<ILayer> layers)
193189
}
194190
save_attributes_to_hdf5_group(g, "weight_names", weight_names.ToArray());
195191
Tensor tensor = null;
196-
string get_Name = "";
197192
foreach (var (name, val) in zip(weight_names, weights)) {
198-
get_Name = name;
193+
199194
tensor = val.AsTensor();
200-
if (get_Name.IndexOf("/") > 1)
195+
if (name.IndexOf("/") > 1)
201196
{
202-
get_Name = name.Split('/')[1];
203-
crDataGroup = Hdf5.CreateOrOpenGroup(g, Hdf5Utils.NormalizedName(get_Name));
197+
crDataGroup = Hdf5.CreateOrOpenGroup(g, Hdf5Utils.NormalizedName(name.Split('/')[0]));
198+
WriteDataset(crDataGroup, name.Split('/')[1], tensor);
204199
Hdf5.CloseGroup(crDataGroup);
205200
}
206-
WriteDataset(g, get_Name, tensor);
201+
else {
202+
WriteDataset(crDataGroup, name, tensor);
203+
}
204+
207205
tensor = null;
208206
}
209207
Hdf5.CloseGroup(g);

0 commit comments

Comments
 (0)