Issue
While working with the code of SRGAN, I wanted to replace UpSampling2D
by tf.image.resize_bicubic
. I used keras lambda layer for this function, as below
def bicubic_lambda(input_shape, scale=2):
shp = input_shape
def outshape(input_shape):
dims = [input_shape[0],input_shape[1] * scale,input_shape[2] * scale,input_shape[3]]
output_shape = tuple(dims)
return output_shape
def bic(x):
return image.resize_images(x, [shp[1]*scale,shp[2]*scale], method=image.ResizeMethod.BICUBIC)
return Lambda(bic, output_shape=outshape, name='bicubic_lambda')
it trains well with out any error but the issue is that I can not save the model. the generator.save(model_save_dir + 'gen_model%d.h5' % e)
causes an error TypeError('Not JSON Serializable: %s' % (obj,))
The code works find with UpSampling2d. my tf version is 1.14.0 and keras 2.3.1. please help :)
Solution
here is a one liner solution.
model = Lambda(lambda image: tf.image.resize_images(image, (image.shape[1]*2, image.shape[2]*2), method = tf.image.ResizeMethod.BICUBIC))(model)
Answered By - Safi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.