Giter VIP home page Giter VIP logo

Comments (2)

achalshah20 avatar achalshah20 commented on August 22, 2024

Any update on releasing keras version? Thanks!

from subpixel.

StanislasBertrand avatar StanislasBertrand commented on August 22, 2024

If youre using keras with tensorflow backend, you can use the given code to create a lambda layer doing the PS operation

check out lambda layers :
https://keras.io/layers/core/#lambda

And the code, i just changed the reshape and split lines to fit latest tensorflow version

def _phase_shift(I, r):
    input_shape = tf.shape(I)
    bsize = input_shape[0]
    a = input_shape[1]
    b = input_shape[2]
    c = input_shape[3]
    shape = tf.stack([bsize,a,b,r,r])

    input_shape_as_numbers = I.get_shape()

    X = tf.reshape(tensor=I, shape=shape)
    X = tf.transpose(X, (0, 1, 2, 4, 3))  # bsize, a, b, 1, 1
    X = tf.split(X, input_shape_as_numbers[1], axis=1)  # a, [bsize, b, r, r]
    X = tf.concat([tf.squeeze(x) for x in X], axis=2)  # bsize, b, a*r, r
    X = tf.split(X,input_shape_as_numbers[2], axis=1)  # b, [bsize, a*r, r]
    X = tf.concat([tf.squeeze(x) for x in X], axis=2)  # bsize, a*r, b*r
    return tf.reshape(X, (bsize, a*r, b*r, 1))

def PS(input_shape, r, color=False):

	def subpixel_shape(input_shape):
		dims = [input_shape[0],
			input_shape[1] * r,
			input_shape[2] * r,
			int(input_shape[3] / (r ** 2))]
		output_shape = tuple(dims)
		return output_shape
  
	def subpixel(x):
		if color:
			Xc = tf.split(3, 3, X)
			X = tf.concat(3, [_phase_shift(x, r) for x in Xc])
		else:
			x_upsampled = _phase_shift(x, r)
		return x_upsampled

	return Lambda(subpixel, output_shape=subpixel_shape, name='subpixel')

Then you would add this layer in a model this way :
upSampled = PS(x_LR.shape, 3, color=False)(x_LR)

from subpixel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.