cloudyr / googleCloudVisionR

Google Cloud Vision API to R
https://cloudyr.github.io/googleCloudVisionR/
Other
6 stars 2 forks source link

`gcv_get_image_annotations()` fails when an error occurs in a later batch and earlier batches were error-free #6

Open tkoncz opened 4 years ago

tkoncz commented 4 years ago
library(googleCloudVisionR)

testPath <- tempfile()
testImages <- c(
    "https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg",
    "https://incorrect.image.path"
)

# this works
gcv_get_image_annotations(imagePaths = testImages, batchSize = 2)
#>                                                                                       image_path        mid    description     score topicality error_code                                                                                               error_message         feature
#>  1: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg   /m/04rky         Mammal 0.9890478  0.9890478         NA                                                                                                        <NA> LABEL_DETECTION
#>  2: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg  /m/0bt9lr            Dog 0.9876207  0.9876207         NA                                                                                                        <NA> LABEL_DETECTION
#>  3: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg   /m/09686     Vertebrate 0.9851104  0.9851104         NA                                                                                                        <NA> LABEL_DETECTION
#>  4: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg   /m/0kpmf      Dog breed 0.9838449  0.9838449         NA                                                                                                        <NA> LABEL_DETECTION
#>  5: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg   /m/01z5f        Canidae 0.9765394  0.9765394         NA                                                                                                        <NA> LABEL_DETECTION
#>  6: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg  /m/0d7s3w          Puppy 0.9450111  0.9450111         NA                                                                                                        <NA> LABEL_DETECTION
#>  7: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg   /m/01lrl      Carnivore 0.8226868  0.8226868         NA                                                                                                        <NA> LABEL_DETECTION
#>  8: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg  /m/03yl64  Companion dog 0.7883269  0.7883269         NA                                                                                                        <NA> LABEL_DETECTION
#>  9: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg  /m/05mqq3          Snout 0.7342774  0.7342774         NA                                                                                                        <NA> LABEL_DETECTION
#> 10: https://image.shutterstock.com/image-photo/keep-calm-labrador-cute-puppy-260nw-633162677.jpg /m/0265rtm Sporting Group 0.6977496  0.6977496         NA                                                                                                        <NA> LABEL_DETECTION
#> 11:                                                                 https://incorrect.image.path       <NA>           <NA>        NA         NA          3 The URL does not appear to be accessible by us. Please double check or download the content and pass it in. LABEL_DETECTION

# this fails
gcv_get_image_annotations(imagePaths = testImages, batchSize = 1)
#> Error in rbindlist(.) : 
#> Item 2 has 4 columns, inconsistent with item 1 which has 6 columns. To fill missing columns use fill=TRUE.

unlink(testPath)
MohmedSoudy commented 3 years ago

@tkoncz am trying to use this function but it fails and requires authentication, could you provide me a screenshot of the data returned by the gcv_get_image_annotations function, I think it should be a datatable which the third column is the label (description).

tkoncz commented 3 years ago

Hi @MohmedSoudy!

The Google Cloud Vision API is a pay-for-use service, hence you'll be need to create your authentication details on the Google Cloud Platform.

For more details about the API itself, please see here:

The googleCloudVisionR package uses the googleAuthR package directly to handle authentication, see here for more details: https://code.markedmondson.me/googleAuthR/ .

The gcv_get_image_annotations() function returns different data.table-s, depending on the feature parameter you select. Below is an example with default settings:

image

MohmedSoudy commented 3 years ago

@tkoncz Thank you for your reply, could you please return the output of gcv_get_image_annotations() to an object like

Labels <- gcv_get_image_annotations()
View(Labels)
tkoncz commented 3 years ago

Not sure how's that different from the screenshot above (or the original issue opened)?

If you need further help pls open a separate issue, as this one is for a specific bug