graphlab SArray Error

User 2570 | 6/28/2016, 8:02:36 AM

Error reading am image form url using the function

sf['img'] = sf['imUrl'].apply(lambda x: gl.Image(x))

errror:

C:\Anaconda2\lib\site-packages\graphlab\datastructures\sarray.pyc in apply(self, fn, dtype, skipundefined, seed) 1853 assert callable(fn), "Input function must be callable." 1854 -> 1855 dryrun = [fn(i) for i in self.head(100) if i is not None] 1856 if dtype == None: 1857 dtype = infertypeof_list(dryrun)

<ipython-input-8-9eb47a22ba77> in <lambda>(x) ----> 1 sf['img'] = sf['imUrl'].apply(lambda x: gl.Image(x))

C:\Anaconda2\lib\site-packages\graphlab\datastructures\image.pyc in init(self, path, format, **Imageinternalkwargs) 70 from ..util import makeinternalurl 71 from .. import extensions as extensions ---> 72 img = extensions.loadimage(makeinternal_url(path), format) 73 for key, value in list(img.dict__.items()): 74 setattr(self, key, value)

C:\Anaconda2\lib\site-packages\graphlab\extensions.pyc in <lambda>(*args, kwargs) 166 167 def makeinjected_function(fn, arguments): --> 168 return lambda *args, kwargs: runtoolkitfunction(fn, arguments, args, kwargs) 169 170 def classinstancefromname(classname, *arg, **kwarg):

C:\Anaconda2\lib\site-packages\graphlab\extensions.pyc in runtoolkitfunction(fnname, arguments, args, kwargs) 155 if ret[0] != True: 156 if len(ret[1]) > 0: --> 157 raise ToolkitError(ret[1]) 158 else: 159 raise _ToolkitError("Toolkit failed with unknown error")

ToolkitError: Unsupported image format. Supported formats are JPG and PNG

@piotr

Comments

User 16 | 6/29/2016, 12:20:15 AM

Per the error message, it sounds like your image isn't a JPG or a PNG. Only those two are supported. Are you certain it's one of those?


User 2570 | 6/30/2016, 5:35:37 PM

@Toby how do I by pass unsupported images, when I pass the functions


User 16 | 6/30/2016, 6:08:35 PM

Assuming the url has the correct file extension, you could do something like this:

sf['img'] = sf['imUrl'].apply( lambda x: gl.Image(x) if x.endswith('.jpg') or x.endswith('.png') else None)