pkmital / CADL

ARCHIVED: Contains historical course materials/Homework materials for the FREE MOOC course on "Creative Applications of Deep Learning w/ Tensorflow" #CADL
https://www.kadenze.com/courses/creative-applications-of-deep-learning-with-tensorflow/info
Apache License 2.0
1.48k stars 732 forks source link

TypeError: Cannot cast ufunc multiply output from dtype('float64') to dtype('int64') with casting rule 'same_kind' #34

Closed clu5 closed 7 years ago

clu5 commented 7 years ago

I get a type error when trying to generate image from random noise in the ipython notebook. Numpy seems to have a problem with upcasting the datatypes.

TypeError                                 Traceback (most recent call last)
<ipython-input-48-b06014ec4265> in <module>()
      1 # Create some noise, centered at gray
      2 img_noise = inception.preprocess(
----> 3     (np.random.randint(100, 150, size=(224, 224, 3))))[np.newaxis]
      4 print(img_noise.min(), img_noise.max())

/home/clu/Python/CADL-master/session-4/libs/inception.py in preprocess(img, crop, resize, dsize)
     81 def preprocess(img, crop=True, resize=True, dsize=(299, 299)):
     82     if img.dtype != np.uint8:
---> 83         img *= 255
     84 
     85     if crop:

`

pkmital commented 7 years ago

Will try to include better type checking. Can you use np.random.randint(100, 150, size=(224, 224, 3), dtype=np.uint8) for now?

clu5 commented 7 years ago

Okay, thanks for the quick fix.