forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaver.cs
More file actions
401 lines (369 loc) · 14.2 KB
/
Saver.cs
File metadata and controls
401 lines (369 loc) · 14.2 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: saver.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace Tensorflow {
/// <summary>Holder for reflection information generated from saver.proto</summary>
public static partial class SaverReflection {
#region Descriptor
/// <summary>File descriptor for saver.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static SaverReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"CgtzYXZlci5wcm90bxIKdGVuc29yZmxvdyKeAgoIU2F2ZXJEZWYSHAoUZmls",
"ZW5hbWVfdGVuc29yX25hbWUYASABKAkSGAoQc2F2ZV90ZW5zb3JfbmFtZRgC",
"IAEoCRIXCg9yZXN0b3JlX29wX25hbWUYAyABKAkSEwoLbWF4X3RvX2tlZXAY",
"BCABKAUSDwoHc2hhcmRlZBgFIAEoCBIlCh1rZWVwX2NoZWNrcG9pbnRfZXZl",
"cnlfbl9ob3VycxgGIAEoAhI9Cgd2ZXJzaW9uGAcgASgOMiwudGVuc29yZmxv",
"dy5TYXZlckRlZi5DaGVja3BvaW50Rm9ybWF0VmVyc2lvbiI1ChdDaGVja3Bv",
"aW50Rm9ybWF0VmVyc2lvbhIKCgZMRUdBQ1kQABIGCgJWMRABEgYKAlYyEAJC",
"ZQoTb3JnLnRlbnNvcmZsb3cudXRpbEILU2F2ZXJQcm90b3NQAVo8Z2l0aHVi",
"LmNvbS90ZW5zb3JmbG93L3RlbnNvcmZsb3cvdGVuc29yZmxvdy9nby9jb3Jl",
"L3Byb3RvYnVm+AEBYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Tensorflow.SaverDef), global::Tensorflow.SaverDef.Parser, new[]{ "FilenameTensorName", "SaveTensorName", "RestoreOpName", "MaxToKeep", "Sharded", "KeepCheckpointEveryNHours", "Version" }, null, new[]{ typeof(global::Tensorflow.SaverDef.Types.CheckpointFormatVersion) }, null)
}));
}
#endregion
}
#region Messages
/// <summary>
/// Protocol buffer representing the configuration of a Saver.
/// </summary>
public sealed partial class SaverDef : pb::IMessage<SaverDef> {
private static readonly pb::MessageParser<SaverDef> _parser = new pb::MessageParser<SaverDef>(() => new SaverDef());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<SaverDef> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::Tensorflow.SaverReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public SaverDef() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public SaverDef(SaverDef other) : this() {
filenameTensorName_ = other.filenameTensorName_;
saveTensorName_ = other.saveTensorName_;
restoreOpName_ = other.restoreOpName_;
maxToKeep_ = other.maxToKeep_;
sharded_ = other.sharded_;
keepCheckpointEveryNHours_ = other.keepCheckpointEveryNHours_;
version_ = other.version_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public SaverDef Clone() {
return new SaverDef(this);
}
/// <summary>Field number for the "filename_tensor_name" field.</summary>
public const int FilenameTensorNameFieldNumber = 1;
private string filenameTensorName_ = "";
/// <summary>
/// The name of the tensor in which to specify the filename when saving or
/// restoring a model checkpoint.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string FilenameTensorName {
get { return filenameTensorName_; }
set {
filenameTensorName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "save_tensor_name" field.</summary>
public const int SaveTensorNameFieldNumber = 2;
private string saveTensorName_ = "";
/// <summary>
/// The operation to run when saving a model checkpoint.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string SaveTensorName {
get { return saveTensorName_; }
set {
saveTensorName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "restore_op_name" field.</summary>
public const int RestoreOpNameFieldNumber = 3;
private string restoreOpName_ = "";
/// <summary>
/// The operation to run when restoring a model checkpoint.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string RestoreOpName {
get { return restoreOpName_; }
set {
restoreOpName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "max_to_keep" field.</summary>
public const int MaxToKeepFieldNumber = 4;
private int maxToKeep_;
/// <summary>
/// Maximum number of checkpoints to keep. If 0, no checkpoints are deleted.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int MaxToKeep {
get { return maxToKeep_; }
set {
maxToKeep_ = value;
}
}
/// <summary>Field number for the "sharded" field.</summary>
public const int ShardedFieldNumber = 5;
private bool sharded_;
/// <summary>
/// Shard the save files, one per device that has Variable nodes.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Sharded {
get { return sharded_; }
set {
sharded_ = value;
}
}
/// <summary>Field number for the "keep_checkpoint_every_n_hours" field.</summary>
public const int KeepCheckpointEveryNHoursFieldNumber = 6;
private float keepCheckpointEveryNHours_;
/// <summary>
/// How often to keep an additional checkpoint. If not specified, only the last
/// "max_to_keep" checkpoints are kept; if specified, in addition to keeping
/// the last "max_to_keep" checkpoints, an additional checkpoint will be kept
/// for every n hours of training.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public float KeepCheckpointEveryNHours {
get { return keepCheckpointEveryNHours_; }
set {
keepCheckpointEveryNHours_ = value;
}
}
/// <summary>Field number for the "version" field.</summary>
public const int VersionFieldNumber = 7;
private global::Tensorflow.SaverDef.Types.CheckpointFormatVersion version_ = 0;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::Tensorflow.SaverDef.Types.CheckpointFormatVersion Version {
get { return version_; }
set {
version_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as SaverDef);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(SaverDef other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (FilenameTensorName != other.FilenameTensorName) return false;
if (SaveTensorName != other.SaveTensorName) return false;
if (RestoreOpName != other.RestoreOpName) return false;
if (MaxToKeep != other.MaxToKeep) return false;
if (Sharded != other.Sharded) return false;
if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(KeepCheckpointEveryNHours, other.KeepCheckpointEveryNHours)) return false;
if (Version != other.Version) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (FilenameTensorName.Length != 0) hash ^= FilenameTensorName.GetHashCode();
if (SaveTensorName.Length != 0) hash ^= SaveTensorName.GetHashCode();
if (RestoreOpName.Length != 0) hash ^= RestoreOpName.GetHashCode();
if (MaxToKeep != 0) hash ^= MaxToKeep.GetHashCode();
if (Sharded != false) hash ^= Sharded.GetHashCode();
if (KeepCheckpointEveryNHours != 0F) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(KeepCheckpointEveryNHours);
if (Version != 0) hash ^= Version.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
if (FilenameTensorName.Length != 0) {
output.WriteRawTag(10);
output.WriteString(FilenameTensorName);
}
if (SaveTensorName.Length != 0) {
output.WriteRawTag(18);
output.WriteString(SaveTensorName);
}
if (RestoreOpName.Length != 0) {
output.WriteRawTag(26);
output.WriteString(RestoreOpName);
}
if (MaxToKeep != 0) {
output.WriteRawTag(32);
output.WriteInt32(MaxToKeep);
}
if (Sharded != false) {
output.WriteRawTag(40);
output.WriteBool(Sharded);
}
if (KeepCheckpointEveryNHours != 0F) {
output.WriteRawTag(53);
output.WriteFloat(KeepCheckpointEveryNHours);
}
if (Version != 0) {
output.WriteRawTag(56);
output.WriteEnum((int) Version);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (FilenameTensorName.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(FilenameTensorName);
}
if (SaveTensorName.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(SaveTensorName);
}
if (RestoreOpName.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(RestoreOpName);
}
if (MaxToKeep != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(MaxToKeep);
}
if (Sharded != false) {
size += 1 + 1;
}
if (KeepCheckpointEveryNHours != 0F) {
size += 1 + 4;
}
if (Version != 0) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Version);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(SaverDef other) {
if (other == null) {
return;
}
if (other.FilenameTensorName.Length != 0) {
FilenameTensorName = other.FilenameTensorName;
}
if (other.SaveTensorName.Length != 0) {
SaveTensorName = other.SaveTensorName;
}
if (other.RestoreOpName.Length != 0) {
RestoreOpName = other.RestoreOpName;
}
if (other.MaxToKeep != 0) {
MaxToKeep = other.MaxToKeep;
}
if (other.Sharded != false) {
Sharded = other.Sharded;
}
if (other.KeepCheckpointEveryNHours != 0F) {
KeepCheckpointEveryNHours = other.KeepCheckpointEveryNHours;
}
if (other.Version != 0) {
Version = other.Version;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(pb::CodedInputStream input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
FilenameTensorName = input.ReadString();
break;
}
case 18: {
SaveTensorName = input.ReadString();
break;
}
case 26: {
RestoreOpName = input.ReadString();
break;
}
case 32: {
MaxToKeep = input.ReadInt32();
break;
}
case 40: {
Sharded = input.ReadBool();
break;
}
case 53: {
KeepCheckpointEveryNHours = input.ReadFloat();
break;
}
case 56: {
version_ = (global::Tensorflow.SaverDef.Types.CheckpointFormatVersion) input.ReadEnum();
break;
}
}
}
}
#region Nested types
/// <summary>Container for nested types declared in the SaverDef message type.</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static partial class Types {
/// <summary>
/// A version number that identifies a different on-disk checkpoint format.
/// Usually, each subclass of BaseSaverBuilder works with a particular
/// version/format. However, it is possible that the same builder may be
/// upgraded to support a newer checkpoint format in the future.
/// </summary>
public enum CheckpointFormatVersion {
/// <summary>
/// Internal legacy format.
/// </summary>
[pbr::OriginalName("LEGACY")] Legacy = 0,
/// <summary>
/// Deprecated format: tf.Saver() which works with tensorflow::table::Table.
/// </summary>
[pbr::OriginalName("V1")] V1 = 1,
/// <summary>
/// Current format: more efficient.
/// </summary>
[pbr::OriginalName("V2")] V2 = 2,
}
}
#endregion
}
#endregion
}
#endregion Designer generated code