我正在尝试根据算法Pix2Pix
对神经网络进行编程。一开始,当我调用TensorFlow
的函数时,会出现错误,并且我不知道如何解决。
我调用的函数:
IMG_WIDTH = 256
IMG_HEIGHT = 256
def resize(inimg, tgimg, height, width):
inimg = tf.image.resize(inimg, [height, width])
tgimg = tf.image.resize(tgimg, [height, width])
return inimg, tgimg
def normalize(inimg, tgimg):
inimg = (inimg / 127.5) - 1
tgimg = (tgimg/127.5) - 1
return inimg, tgimg
def load_image(filename, augment=True):
inimg = tf.cast(tf.image.decode_jpeg(tf.io.read_file(INPATH + "/" + filename)), tf.float32)[..., :3]
tgimg = tf.cast(tf.image.decode_jpeg(tf.io.read_file(OUTPATH + "/" + filename)), tf.float32)[..., :3]
inimg, tgimg = resize(inimg, tgimg, IMG_HEIGHT, IMG_WIDTH)
inimg, tgimg = normalize(inimg, tgimg)
return inimg, tgimg
def load_train_image(filename):
return load_image(filename, True)
def load_test_image(filename):
return load_image(filename, False)
plt.imshow(((load_train_image(randurls[0])[0]) + 1)/ 2)
最后,我想查看数据库加载的结果,但出现此错误:
NotImplementedError Traceback (most recent call last)
<ipython-input-15-748ce6c46d5c> in <module>()
31 return load_image(filename, False)
32
---> 33 plt.imshow(((load_train_image(randurls[0])[0]) + 1)/ 2)
/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, data, **kwargs)
2675 filternorm=filternorm, filterrad=filterrad, imlim=imlim,
2676 resample=resample, url=url, **({"data": data} if data is not
-> 2677 None else {}), **kwargs)
2678 sci(__ret)
2679 return __ret
/usr/local/lib/python3.6/dist-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
1597 def inner(ax, *args, data=None, **kwargs):
1598 if data is None:
-> 1599 return func(ax, *map(sanitize_sequence, args), **kwargs)
1600
1601 bound = new_sig.bind(ax, *args, **kwargs)
/usr/local/lib/python3.6/dist-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs)
367 f"%(removal)s. If any parameter follows {name!r}, they "
368 f"should be pass as keyword, not positionally.")
--> 369 return func(*args, **kwargs)
370
371 return wrapper
/usr/local/lib/python3.6/dist-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs)
367 f"%(removal)s. If any parameter follows {name!r}, they "
368 f"should be pass as keyword, not positionally.")
--> 369 return func(*args, **kwargs)
370
371 return wrapper
/usr/local/lib/python3.6/dist-packages/matplotlib/axes/_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
5677 resample=resample, **kwargs)
5678
-> 5679 im.set_data(X)
5680 im.set_alpha(alpha)
5681 if im.get_clip_path() is None:
/usr/local/lib/python3.6/dist-packages/matplotlib/image.py in set_data(self, A)
678 if isinstance(A, Image.Image):
679 A = pil_to_array(A) # Needed e.g. to apply png palette.
--> 680 self._A = cbook.safe_masked_invalid(A, copy=True)
681
682 if (self._A.dtype != np.uint8 and
/usr/local/lib/python3.6/dist-packages/matplotlib/cbook/__init__.py in safe_masked_invalid(x, copy)
793
794 def safe_masked_invalid(x, copy=False):
--> 795 x = np.array(x, subok=True, copy=copy)
796 if not x.dtype.isnative:
797 # Note that the argument to `byteswap` is 'inplace',
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py in __array__(self)
734 def __array__(self):
735 raise NotImplementedError("Cannot convert a symbolic Tensor ({}) to a numpy"
--> 736 " array.".format(self.name))
737
738 def __len__(self):
NotImplementedError: Cannot convert a symbolic Tensor (truediv_17:0) to a numpy array.