AI-PredictionClient
view release on metacpan or search on metacpan
lib/AI/PredictionClient/Classes/SimpleTensor.pm view on Meta::CPAN
default => 0,
);
has dtype_values => (
is => 'ro',
default => sub {
{
DT_HALF => 'halfVal',
DT_FLOAT => 'floatVal',
DT_DOUBLE => 'doubleVal',
DT_INT16 => 'intVal',
DT_INT8 => 'intVal',
DT_UINT8 => 'intVal',
DT_STRING => 'stringVal',
DT_COMPLEX64 => 'scomplexVal',
DT_INT64 => 'int64Val',
DT_BOOL => 'boolVal',
DT_COMPLEX128 => 'dcomplexVal',
DT_RESOURCE => 'resourceHandleVal'
};
});
sub value {
my ($self, $value_aref) = @_;
my $decoded_aref;
my $value_type = $self->dtype_values->{ $self->dtype };
my $tensor_value_ref = \$self->tensor_ds->{$value_type};
if ($value_aref) {
if ($self->dtype eq 'DT_STRING' && !$self->use_base64_strings) {
@$$tensor_value_ref
= map { encode_base64(ref($_) ? $$_ : $_, '') } @$value_aref;
} else {
$$tensor_value_ref = $value_aref;
delete $self->tensor_ds->{'stringVal'}
; # When not a string delete convenience placeholder.
}
return [];
} else {
if ($self->dtype eq 'DT_STRING' && !$self->use_base64_strings) {
@$decoded_aref = map { decode_base64($_) } @$$tensor_value_ref;
return $decoded_aref;
} else {
return $$tensor_value_ref;
}
}
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
AI::PredictionClient::Classes::SimpleTensor - A simplified version of the TensorFlow Tensor proto.
=head1 VERSION
version 0.05
=head1 AUTHOR
Tom Stall <stall@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Tom Stall.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 1.231 second using v1.01-cache-2.11-cpan-5735350b133 )