示例#1
0
func (n Network) Serialize() ([]byte, error) {
	serializers := make([]serializer.Serializer, len(n))
	for i, x := range n {
		serializers[i] = x
	}
	return serializer.SerializeSlice(serializers)
}
示例#2
0
// Serialize attempts to serialize b.
// This fails if any of the seqfunc.RFuncs are not
// serializer.Serializers.
func (b *Bidirectional) Serialize() ([]byte, error) {
	var slice []serializer.Serializer
	for _, x := range []seqfunc.RFunc{b.Forward, b.Backward, b.Output} {
		s, ok := x.(serializer.Serializer)
		if !ok {
			return nil, fmt.Errorf("type cannot be serialized: %T", x)
		}
		slice = append(slice, s)
	}
	return serializer.SerializeSlice(slice)
}
示例#3
0
文件: lstm.go 项目: unixpickle/weakai
func (l *lstmGate) Serialize() ([]byte, error) {
	slist := []serializer.Serializer{l.Dense, l.Activation}
	if l.Peephole != nil {
		data, err := json.Marshal(l.Peephole)
		if err != nil {
			return nil, err
		}
		slist = append(slist, serializer.Bytes(data))
	}
	return serializer.SerializeSlice(slist)
}
示例#4
0
// Serialize attempts to serialize all of the sub-blocks
// if they implement the Serializer interface.
func (s StackedBlock) Serialize() ([]byte, error) {
	serializers := make([]serializer.Serializer, len(s))
	for i, l := range s {
		if ser, ok := l.(serializer.Serializer); ok {
			serializers[i] = ser
		} else {
			return nil, fmt.Errorf("layer %d (%T) is not a Serializer", i, l)
		}
	}
	return serializer.SerializeSlice(serializers)
}
示例#5
0
// Serialize serializes the block.
func (n *NetworkBlock) Serialize() ([]byte, error) {
	initData, err := json.Marshal(n.batcherBlock.Start)
	if err != nil {
		return nil, err
	}
	serializers := []serializer.Serializer{
		serializer.Int(n.batcherBlock.StateSize),
		n.network,
		serializer.Bytes(initData),
	}
	return serializer.SerializeSlice(serializers)
}
示例#6
0
文件: gru.go 项目: unixpickle/weakai
// Serialize serializes the block.
func (g *GRU) Serialize() ([]byte, error) {
	initData, err := json.Marshal(g.initState)
	if err != nil {
		return nil, err
	}
	slist := []serializer.Serializer{
		serializer.Int(g.hiddenSize),
		g.inputValue,
		g.resetGate,
		g.updateGate,
		serializer.Bytes(initData),
	}
	return serializer.SerializeSlice(slist)
}
示例#7
0
文件: lstm.go 项目: unixpickle/weakai
// Serialize serializes the LSTM.
func (l *LSTM) Serialize() ([]byte, error) {
	initData, err := json.Marshal(l.initState)
	if err != nil {
		return nil, err
	}
	slist := []serializer.Serializer{
		serializer.Int(l.hiddenSize),
		l.inputValue,
		l.inputGate,
		l.rememberGate,
		l.outputGate,
		serializer.Bytes(initData),
	}
	return serializer.SerializeSlice(slist)
}