Git Product home page Git Product logo

Comments (3)

genekogan avatar genekogan commented on May 25, 2024 2

PR submitted here. let me know if it works.
thanks for this codebase!!

from dcgan-tensorflow.

genekogan avatar genekogan commented on May 25, 2024

i figured this out by making the generator's size a function of the image's size. this is working for me at any resolution, unsupervised or supervised.

i can submit a PR if it would be helpful.

`

def generator(self, z, y=None):
    if not self.y_dim:

        w = int(self.image_shape[0])
        w2, w4, w8, w16 = int(w/2), int(w/4), int(w/8), int(w/16)

        # project `z` and reshape
        self.z_, self.h0_w, self.h0_b = linear(z, self.gf_dim*8*w16*w16, 'g_h0_lin', with_w=True)

        self.h0 = tf.reshape(self.z_, [-1, w16, w16, self.gf_dim * 8])
        h0 = tf.nn.relu(self.g_bn0(self.h0))

        self.h1, self.h1_w, self.h1_b = deconv2d(h0, 
            [self.batch_size, w8, w8, self.gf_dim*4], name='g_h1', with_w=True)
        h1 = tf.nn.relu(self.g_bn1(self.h1))

        h2, self.h2_w, self.h2_b = deconv2d(h1,
            [self.batch_size, w4, w4, self.gf_dim*2], name='g_h2', with_w=True)
        h2 = tf.nn.relu(self.g_bn2(h2))

        h3, self.h3_w, self.h3_b = deconv2d(h2,
            [self.batch_size, w2, w2, self.gf_dim*1], name='g_h3', with_w=True)
        h3 = tf.nn.relu(self.g_bn3(h3))

        h4, self.h4_w, self.h4_b = deconv2d(h3,
            [self.batch_size, w, w, self.c_dim], name='g_h4', with_w=True)

        return tf.nn.tanh(h4)
    else:
        w = int(self.image_shape[0])
        w2, w4 = int(w/2), int(w/4) 

        # yb = tf.expand_dims(tf.expand_dims(y, 1),2)
        yb = tf.reshape(y, [self.batch_size, 1, 1, self.y_dim])
        z = tf.concat(1, [z, y])

        h0 = tf.nn.relu(self.g_bn0(linear(z, self.gfc_dim, 'g_h0_lin')))
        h0 = tf.concat(1, [h0, y])

        h1 = tf.nn.relu(self.g_bn1(linear(z, self.gf_dim*2*w4*w4, 'g_h1_lin')))            
        h1 = tf.reshape(h1, [self.batch_size, w4, w4, self.gf_dim * 2])

        h1 = conv_cond_concat(h1, yb)

        h2 = tf.nn.relu(self.g_bn2(deconv2d(h1, [self.batch_size, w2, w2, self.gf_dim * 2], name='g_h2')))
        h2 = conv_cond_concat(h2, yb)

        return tf.nn.sigmoid(deconv2d(h2, [self.batch_size, w, w, self.c_dim], name='g_h3'))

def sampler(self, z, y=None):
    tf.get_variable_scope().reuse_variables()

    if not self.y_dim:

        w = int(self.image_shape[0])
        w2, w4, w8, w16 = int(w/2), int(w/4), int(w/8), int(w/16)

        # project `z` and reshape
        h0 = tf.reshape(linear(z, self.gf_dim*8*w16*w16, 'g_h0_lin'),
                        [-1, w16, w16, self.gf_dim * 8])
        h0 = tf.nn.relu(self.g_bn0(h0, train=False))

        h1 = deconv2d(h0, [self.batch_size, w8, w8, self.gf_dim*4], name='g_h1')
        h1 = tf.nn.relu(self.g_bn1(h1, train=False))

        h2 = deconv2d(h1, [self.batch_size, w4, w4, self.gf_dim*2], name='g_h2')
        h2 = tf.nn.relu(self.g_bn2(h2, train=False))

        h3 = deconv2d(h2, [self.batch_size, w2, w2, self.gf_dim*1], name='g_h3')
        h3 = tf.nn.relu(self.g_bn3(h3, train=False))

        h4 = deconv2d(h3, [self.batch_size, w, w, self.c_dim], name='g_h4')

        return tf.nn.tanh(h4)
    else:
        w = self.image_shape[0]
        w2, w4 = int(w/2), int(w/4)

        #yb = tf.reshape(y, [-1, 1, 1, self.y_dim])
        yb = tf.reshape(y, [self.batch_size, 1, 1, self.y_dim])

        z = tf.concat(1, [z, y])

        h0 = tf.nn.relu(self.g_bn0(linear(z, self.gfc_dim, 'g_h0_lin')))
        h0 = tf.concat(1, [h0, y])

        h1 = tf.nn.relu(self.g_bn1(linear(z, self.gf_dim*2*w4*w4, 'g_h1_lin'), train=False))
        h1 = tf.reshape(h1, [self.batch_size, w4, w4, self.gf_dim * 2])
        h1 = conv_cond_concat(h1, yb)

        h2 = tf.nn.relu(self.g_bn2(deconv2d(h1, [self.batch_size, w2, w2, self.gf_dim * 2], name='g_h2'), train=False))
        h2 = conv_cond_concat(h2, yb)

        return tf.nn.sigmoid(deconv2d(h2, [self.batch_size, w, w, self.c_dim], name='g_h3'))

`

from dcgan-tensorflow.

carpedm20 avatar carpedm20 commented on May 25, 2024

@genekogan Yes, please. It would be helpful! Thanks.

from dcgan-tensorflow.

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.