forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.Build.cs
More file actions
51 lines (48 loc) · 1.91 KB
/
Model.Build.cs
File metadata and controls
51 lines (48 loc) · 1.91 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
using System;
using System.Linq;
using Tensorflow.Graphs;
using Tensorflow.Keras.Saving;
using Tensorflow.Keras.Utils;
using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
namespace Tensorflow.Keras.Engine
{
public partial class Model
{
public override void build(KerasShapesWrapper input_shape)
{
if (_is_graph_network || this is Functional || this is Sequential)
{
base.build(input_shape);
return;
}
if(input_shape is not null && this.inputs is null)
{
var graph = tf.executing_eagerly() ? new FuncGraph("build_graph") : keras.backend.get_graph();
graph.as_default();
var shapes = input_shape.ToShapeArray();
var x = new Tensors(shapes.Select(x => base_layer_utils.generate_placeholders_from_shape(x)).ToArray());
try
{
Call(x, training: false);
}
catch (InvalidArgumentError)
{
throw new ValueError("You cannot build your model by calling `build` " +
"if your layers do not support float type inputs. " +
"Instead, in order to instantiate and build your " +
"model, `call` your model on real tensor data (of the correct dtype).");
}
catch (TypeError)
{
throw new ValueError("You cannot build your model by calling `build` " +
"if your layers do not support float type inputs. " +
"Instead, in order to instantiate and build your " +
"model, `call` your model on real tensor data (of the correct dtype).");
}
graph.Exit();
}
base.build(input_shape);
}
}
}