AI-PredictionClient

 view release on metacpan or  search on metacpan

LICENSE  view on Meta::CPAN

    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA


Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) 19xx name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License.  Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here a sample; alter the names:

MANIFEST  view on Meta::CPAN

MANIFEST
META.json
META.yml
Makefile.PL
README
bin/Inception.pl
cpanfile
dist.ini
lib/AI/PredictionClient.pm
lib/AI/PredictionClient/CPP/PredictionGrpcCpp.pm
lib/AI/PredictionClient/CPP/Typemaps/more_typemaps_STL_String.txt
lib/AI/PredictionClient/Classes/SimpleTensor.pm
lib/AI/PredictionClient/Docs/Overview.pod
lib/AI/PredictionClient/InceptionClient.pm
lib/AI/PredictionClient/Predict.pm
lib/AI/PredictionClient/Roles/PredictRole.pm
lib/AI/PredictionClient/Roles/PredictionRole.pm
lib/AI/PredictionClient/Testing/Camel.pm
lib/AI/PredictionClient/Testing/PredictionLoopback.pm
t/00load.t
t/author-critic.t

META.json  view on Meta::CPAN

      },
      "AI::PredictionClient::Testing::PredictionLoopback" : {
         "file" : "lib/AI/PredictionClient/Testing/PredictionLoopback.pm",
         "version" : "0.05"
      }
   },
   "release_status" : "stable",
   "resources" : {
      "homepage" : "https://github.com/mountaintom/AI-PredictionClient",
      "repository" : {
         "type" : "git",
         "url" : "https://github.com/mountaintom/AI-PredictionClient.git",
         "web" : "https://github.com/mountaintom/AI-PredictionClient"
      }
   },
   "version" : "0.05",
   "x_serialization_backend" : "Cpanel::JSON::XS version 3.0233"
}

dist.ini  view on Meta::CPAN

header = die 'Unsupported OS' if $^O eq 'MSWin32';
header = use Inline::MakeMaker;

[CPANFile]
[MetaJSON]
[PkgVersion]
[AutoPrereqs]
[PodWeaver]

[ReadmeAnyFromPod]
type = pod
filename = README.pod
location = root

[Prereqs]
perl = 5.01

[Prereqs / ConfigureRequires]
Inline = 0
Inline::CPP = 0
Inline::MakeMaker = 0

lib/AI/PredictionClient/CPP/PredictionGrpcCpp.pm  view on Meta::CPAN

# ABSTRACT: The C++ interface to gRPC and Protocol Buffers

use Cwd;
use Alien::Google::GRPC;
use AI::PredictionClient::Alien::TensorFlowServingProtos;
use Inline
  CPP => 'DATA',
  with => ['Alien::Google::GRPC', 'AI::PredictionClient::Alien::TensorFlowServingProtos'],
  version => '0.05',
  name => 'AI::PredictionClient::CPP::PredictionGrpcCpp',
  TYPEMAPS => getcwd . '/blib/lib/AI/PredictionClient/CPP/Typemaps/more_typemaps_STL_String.txt',
  LIBS => '-ldl',
  ccflags => '-std=c++11 -pthread';

use 5.010;
use strict;
use warnings;

1;

=pod

lib/AI/PredictionClient/Classes/SimpleTensor.pm  view on Meta::CPAN

    return $class->$orig(tensor_ds => $_[0]);
  } else {
    return $class->$orig(@_);
  }
};

has tensor_ds => (
  is      => 'ro',
  default => sub {
    {
      dtype       => "DT_STRING",
      tensorShape => { dim => [ { size => 1 } ] },
      stringVal   => [""] };
  },
);

sub shape {
  my ($self, $shape_aref) = @_;

  my $tensor_shape_ref = \$self->tensor_ds->{"tensorShape"}->{"dim"};
  $$tensor_shape_ref = $shape_aref if $shape_aref;

  return $$tensor_shape_ref;
}

sub dtype {
  my ($self, $dtype) = @_;
  my $tensor_dtype_ref = \$self->tensor_ds->{"dtype"};
  $$tensor_dtype_ref = $dtype if $dtype;

  return $$tensor_dtype_ref;
}

has use_base64_strings => (
  is      => 'rw',
  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',

lib/AI/PredictionClient/Classes/SimpleTensor.pm  view on Meta::CPAN

      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;

lib/AI/PredictionClient/InceptionClient.pm  view on Meta::CPAN

has inception_results => (is => 'rwp');

has camel => (is => 'rw',);

sub call_inception {
  my $self  = shift;
  my $image = shift;

  my $tensor = AI::PredictionClient::Classes::SimpleTensor->new();
  $tensor->shape([ { size => 1 } ]);
  $tensor->dtype("DT_STRING");

  if ($self->camel) {
    my $camel_test = AI::PredictionClient::Testing::Camel->new();
    $tensor->value([ $camel_test->camel_jpeg_ref ]);
  } else {
    $tensor->value([$image]);
  }

  $self->inputs({ images => $tensor });

lib/AI/PredictionClient/Testing/PredictionLoopback.pm  view on Meta::CPAN

    return $class->$orig(@_);
  }
};

has server_port => (is => 'rw',);

sub callPredict {
  my ($self, $request_data) = @_;

  my $test_return01
    = '{"outputs":{"classes":{"dtype":"DT_STRING","tensorShape":{"dim":[{"size":"1"},{"size":"6"}]},"stringVal":["bG9vcGJhY2sgdGVzdCBkYXRhCg==","bWlsaXRhcnkgdW5pZm9ybQ==","Ym93IHRpZSwgYm93LXRpZSwgYm93dGll","bW9ydGFyYm9hcmQ=","c3VpdCwgc3VpdCBvZiBjbG90...

  my $test_return02
    = '{"outputs":{"classes":{"dtype":"DT_STRING","tensorShape":{"dim":[{"size":"1"},{"size":"5"}]},"stringVal":["bG9hZCBpdAo=","Y2hlY2sgaXQK","cXVpY2sgLSByZXdyaXRlIGl0Cg==","dGVjaG5vbG9naWMK","dGVjaG5vbG9naWMK"]},"scores":{"dtype":"DT_FLOAT","tensor...

  my $return_ser = '{"Status": "OK", ';
  $return_ser .= '"StatusCode": "42", ';
  $return_ser .= '"StatusMessage": "", ';
  $return_ser .= '"DebugRequestLoopback": ' . $request_data . ', ';

  if ($self->server_port eq 'technologic:2004') {
    $return_ser .= '"Result": ' . $test_return02 . '}';
  } else {
    $return_ser .= '"Result": ' . $test_return01 . '}';



( run in 1.766 second using v1.01-cache-2.11-cpan-df04353d9ac )