Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Video Intelligence: Class 'Google\Cloud\Videointelligence\V1\Feature' not found #950

Closed
hypercms opened this issue Mar 26, 2018 · 17 comments
Assignees
Labels
api: videointelligence Issues related to the Video Intelligence API API. type: question Request for information or clarification. Not an issue.

Comments

@hypercms
Copy link

hypercms commented Mar 26, 2018

Running Apache 2.4, PHP7 on Debian 9, Google Video Intelligence API has been installed with composer.
After declaring the features [Feature::LABEL_DETECTION] for the request an error is reported that the class Feature is missing.

Code:
use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient;
use Google\Cloud\Videointelligence\V1\Feature;
....
$video = new VideoIntelligenceServiceClient();
$options = ['inputContent'=>$inputContent, 'features'=>[Feature::LABEL_DETECTION]];
$operation = $video->annotateVideo($options);

Error:
PHP Fatal error: Uncaught Error: Class 'Google\Cloud\Videointelligence\V1\Feature' not found

@dwsupplee dwsupplee added type: question Request for information or clarification. Not an issue. api: videointelligence Issues related to the Video Intelligence API API. labels Mar 26, 2018
@dwsupplee
Copy link
Contributor

Thanks for the report @hypercms. In your vendor directory do you have google/proto-client? It should contain the necessary dependencies, such as the Feature class. The package is required by the Video Intelligence package, so it should be pulled into your project automatically for you when running composer require google/cloud-videointelligence.

Have you tried deleting your vendor directory, removing your composer.lock file (if one exists), and attempting a fresh install?

@hypercms
Copy link
Author

hypercms commented Mar 26, 2018

Thanks for the quick reply. I checked that already and google/proto-client has been included by composer. The class file Feature.php is present and the class looks fine too. So I was suprised it didn't find the class. I manually copied the class to my test PHP file to avoid the error, but that caused another error and I gave up digging deeper.
I am using composer version 1.2.3 that is provided by Debian 9. This version is already more than a year old. Should I manually install the latest version of composer, might the outdated composer causing any issue with the installtion? Since it seems all files have been downloaded I thought it should work.

@dwsupplee
Copy link
Contributor

I doubt an older version of composer would be causing the issue. It could be the casing of the import, could you try VideoIntelligence instead of Videointelligence?

@hypercms
Copy link
Author

Thank you, I really didn't see that. I used a small "i". Of course that won't work on Linux. The class Feature can be found but unfortunately there is a TypeError:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Google\ApiCore\Middleware\RetryMiddleware::Google\ApiCore\Middleware{closure}() must be an instance of Exception, instance of Error given, called in /library/google-cloud-api/guzzlehttp/promises/src/Promise.php on line 203 and defined in /library/google-cloud-api/google/gax/src/ApiCore/Middleware/RetryMiddleware.php:90
Stack trace:
#0 /library/google-cloud-api/guzzlehttp/promises/src/Promise.php(203): Google\ApiCore\Middleware\RetryMiddleware->Google\ApiCore\Middleware{closure}(Object(Error))
#1 /library/google-cloud-api/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(2, Object(Error), Array)
#2 /library/google-cloud-api/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure in /library/google-cloud-api/google/gax/src/ApiCore/Middleware/RetryMiddleware.php on line 90

@dwsupplee
Copy link
Contributor

Could you please share the full snippet which is triggering the error? While on PHP7 I don't get the same issue while running the snippet provided in the original comment.

@hypercms
Copy link
Author

hypercms commented Mar 26, 2018

The error is triggered by $operation->pollUntilComplete(); in the following function:

use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient;
use Google\Cloud\VideoIntelligence\V1\Feature;

function GCanalyzevideo ($path)
{
  global $mgmt_config;
  
  if (!empty ($mgmt_config['gs_access_json']))
  {
    // authenticate
    putenv ("GOOGLE_APPLICATION_CREDENTIALS=".$mgmt_config['gs_access_json']);

    try
    {
      // Instantiate a client
      $video = new VideoIntelligenceServiceClient();

      // Read the local video file
      $inputContent = file_get_contents ($path);

      // Execute a request
      $options = ['inputContent'=>$inputContent, 'features'=>[Feature::LABEL_DETECTION]];
      $operation = $video->annotateVideo($options);

      // Wait for the request to complete
      $operation->pollUntilComplete();

      // Results
      if ($operation->operationSucceeded())
      {
        $results = $operation->getResult()->getAnnotationResults()[0];

        // Process video/segment level label annotations
        foreach ($results->getSegmentLabelAnnotations() as $label)
        {
          $description = $label->getEntity()->getDescription();

          $keywords = array();
          
          foreach ($label->getCategoryEntities() as $categoryEntity)
          {
             $keywords[] = $categoryEntity->getDescription();
          }
          
          $i = 0;
          $result = array();
          
          foreach ($label->getSegments() as $segment)
          {
            $startTimeOffset = $segment->getSegment()->getStartTimeOffset();
            $startSeconds = $startTimeOffset->getSeconds();
            $startNanoseconds = floatval($startTimeOffset->getNanos())/1000000000.00;
            $startTime = $startSeconds + $startNanoseconds;
            $endTimeOffset = $segment->getSegment()->getEndTimeOffset();
            $endSeconds = $endTimeOffset->getSeconds();
            $endNanoseconds = floatval($endTimeOffset->getNanos())/1000000000.00;
            $endTime = $endSeconds + $endNanoseconds;
            
            $result[$i]['starttime'] = $startTime;
            $result[$i]['endtime'] = $endTime;
            $result[$i]['description'] = $description;
            $result[$i]['keywords'] = implode (",", $keywords);
            $result[$i]['confidence'] = $segment->getConfidence();

            $i++;
          }
        }
        
        return $result;
      }
      else return false;
    }
    catch (Exception $e)
    {
      return  false;
    }
  }
  else return false;
}

@dwsupplee
Copy link
Contributor

Thanks @hypercms, I will look into this more.

@dwsupplee
Copy link
Contributor

dwsupplee commented Mar 30, 2018

@hypercms, I ran the provided script on PHP 7.0 and was able to get back results:

array(1) {
  [0] =>
  array(5) {
    'starttime' =>
    double(0)
    'endtime' =>
    double(29.52)
    'description' =>
    string(5) "plant"
    'keywords' =>
    string(0) ""
    'confidence' =>
    double(0.56578069925308)
  }
}

A few questions to help us get to the bottom of this :)

  • Which version of PHP are you using specifically?
  • Have you attempted these requests with gRPC, or are you using REST? If gRPC, do you know which version of the extension you are using?
  • Which version of the library are you using?
  • If you navigate to the following file in your vendor directory and remove the Exception typehint, does a more useful error surface?

@hypercms
Copy link
Author

I am using PHP Version 7.0.27-0+deb9u1 (cli) (built: Jan 5 2018 13:51:52).
I saw that gRPC has been installed by composer. Where can I see if it is actually used? How can I siwtch to the REST API? Sorry, I don't know much about your Cloud API and it's configuration.
I am using Google Video Intelligence Version 0.9.3.
Thank you!

@hypercms
Copy link
Author

hypercms commented Apr 2, 2018

Uninstalled all Google Cloud API packages and uninstalled composer as well. Reinstalled everything, so I am using Google Video Intelligence Version 0.10.0. But there is still the same issue.

@dwsupplee
Copy link
Contributor

@hypercms,

I saw that gRPC has been installed by composer. Where can I see if it is actually used?

We have a gRPC package for PHP which is used to facilitate the gRPC C extension. The PHP package comes for free, but the C extension requires a bit of extra set up. For some more details on gRPC, take a look here to see if it is worthwhile for your use case.

How can I siwtch to the REST API?

It looks like you're already using it, actually.

After a little more research I believe I found the root of the issue here. When installing a fresh copy of PHP on a Compute Engine instance I started to get the same error you have mentioned. This is due to the fact one of our dependencies requires the bcmath extension which does not come with the default PHP 7 install. I have reported this issue on the relevant repository.

While we work on getting this resolved, you have got a few options:

  1. Continue using REST as the transport layer, but you will need to install the bcmath extension - this can be done like so: sudo apt-get install php7.0-bcmath
  2. Switch over to using gRPC as your transport layer. This will circumvent the bcmath related calls. For more details on installing gRPC see here.

Hope this helps, and thanks again for the report :)

@hypercms
Copy link
Author

hypercms commented Apr 2, 2018

I installed bcmath, restarted Apache and it worked :)
Thank you!

@dwsupplee
Copy link
Contributor

Awesome! I'm going to keep this issue open just until we hear back from the protobuf team as to how they would like to handle the situation.

@florianbrinkmann
Copy link

Just had the same problem with the not-found Feature class. In the documentation (https://cloud.google.com/video-intelligence/docs/analyze-labels) it is written Videointelligence with small i, maybe that could be modified :)

@dwsupplee
Copy link
Contributor

Good eye @florianbrinkmann! It looks like the source has been corrected to use the right import, and it may just be a matter of getting those changes propagated out to the documentation site. I'll poke around a bit and see what we can do to get that taken care of :).

@florianbrinkmann
Copy link

Great, thanks @dwsupplee! :)

@dwsupplee dwsupplee added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. gapic api: videointelligence Issues related to the Video Intelligence API API. type: question Request for information or clarification. Not an issue. and removed type: question Request for information or clarification. Not an issue. api: videointelligence Issues related to the Video Intelligence API API. gapic priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 3, 2018
@dwsupplee
Copy link
Contributor

I'm going to close this out now. Please see the issue on the protobuf repository to follow up on #950 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: videointelligence Issues related to the Video Intelligence API API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants