cppn-tensorflow icon indicating copy to clipboard operation
cppn-tensorflow copied to clipboard

TypeError: only integer scalar arrays can be converted to a scalar index

Open whyeverwhy opened this issue 5 years ago • 2 comments

First of all sorry for the rather futile question, I know this doesn't seem specifically about the code itself but couldn't find the solution. My problem is that I can't generate the .gif files due to this error.

TypeErrorTraceback (most recent call last)
<ipython-input-80-2954e669139d> in <module>()
----> 1 sampler.save_anim_gif(z1, z2, 'output.gif')

/content/drive/cppn/sampler.py in save_anim_gif(self, z1, z2, filename, n_frame, duration1, duration2, duration, x_dim, y_dim, scale, reverse)
    115       durations = durations + [duration]*n_frame + [duration1]
    116     print ("writing gif file...")
--> 117     writeGif(filename, images, duration = durations)
    118     im.save(filename)

/content/drive/images2gif.py in writeGif(filename, images, duration, repeat, dither, nq, subRectangles, dispose)
    560     # Check subrectangles
    561     if subRectangles:
--> 562         images, xy = gifWriter.handleSubRectangles(images, subRectangles)
    563         defaultDispose = 1 # Leave image in place
    564     else:

/content/drive/cppn/images2gif.py in handleSubRectangles(self, images, subRectangles)
    298 
    299             # Determine the sub rectangles
--> 300             images, xy = self.getSubRectangles(images)
    301 
    302         # Done

/content/drive/cppn/images2gif.py in getSubRectangles(self, ims)
    350 
    351             # Cut out and store
--> 352             im2 = im[y0:y1,x0:x1]
    353             prev = im
    354             ims2.append(im2)

TypeError: only integer scalar arrays can be converted to a scalar index

My guess was that it is due to version of Tensorflow, so I updated everything [along with the amended version of images2gif.py] but still didn't work.

I really would appreciate any help on this.

Thanks very much for this wonderful thing.

whyeverwhy avatar Jan 01 '19 15:01 whyeverwhy

Same problem, writeGif doesn't seem to work

kadarakos avatar May 30 '19 11:05 kadarakos

Hi @whyeverwhy , this is a python version issue and can be solved with the following changes in the line you are pointing out (within images2gif.py) and the ones immediately above:

# Get rect coordinates
if X.size and Y.size:
    x0, x1 = int(X[0]), int(X[-1]+1)
    y0, y1 = int(Y[0]), int(Y[-1]+1)

and

# Cut out and store
im2 = np.asarray(im)[y0:y1,x0:x1]

alfredolozano avatar Feb 29 '20 17:02 alfredolozano