Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/gan #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion digits/tools/tensorflow/gan_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@
""".split()

CELEBA_EDITABLE_ATTRIBUTES = [
'Bald', 'Black_Hair', 'Blond_Hair', 'Eyeglasses', 'Male', 'Mustache', 'Smiling', 'Young', 'Attractive', 'Pale_Skin', 'Big_Nose'
'Bald', 'Black_Hair', 'Blond_Hair', 'Eyeglasses', 'Mustache', 'Smiling', 'Young', 'Attractive', 'Pale_Skin', 'Big_Nose'
]

CELEBA_EDITABLE_ATTRIBUTES_IDS = [CELEBA_ALL_ATTRIBUTES.index(attr) for attr in CELEBA_EDITABLE_ATTRIBUTES]

GENDER_ATTRIBUTE_ID = CELEBA_ALL_ATTRIBUTES.index('Male')


logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
Expand Down Expand Up @@ -386,6 +388,14 @@ def Inference(sess, model):
for idx, attr_scale in enumerate(attributes):
z += (attr_scale / 25. ) * attribute_zs[CELEBA_EDITABLE_ATTRIBUTES_IDS[idx]]

# gender
gender = app.GetGender()
if gender == 'Male':
gender_attr = 1.
else:
gender_attr = -1.
z += gender_attr * attribute_zs[GENDER_ATTRIBUTE_ID]

feed_dict = {model.time_placeholder: float(t),
model.attribute_placeholder: z}
preds = sess.run(fetches=inference_op, feed_dict=feed_dict)
Expand Down
24 changes: 24 additions & 0 deletions digits/tools/tensorflow/gandisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import wx
import numpy as np
import os
import random
import time

Expand Down Expand Up @@ -191,6 +192,10 @@ def __init__(self, parent=None, grid_size=640, attributes=[]):
vbox.Add(slider_text, 0, wx.ALIGN_CENTRE)
vbox.Add(self.speed_slider, 0, wx.ALIGN_CENTRE)

genders = ['Male', 'Female']
self.gender_box = wx.RadioBox(panel, label='Gender', choices=genders, majorDimension=1, style=wx.RA_SPECIFY_ROWS)
vbox.Add(self.gender_box, 0, wx.ALIGN_CENTRE)

self.attribute_sliders = []
for attribute in attributes:
slider_text = wx.StaticText(panel, label=attribute)
Expand All @@ -200,6 +205,17 @@ def __init__(self, parent=None, grid_size=640, attributes=[]):
vbox.Add(slider, 0, wx.ALIGN_CENTRE)
self.attribute_sliders.append(slider)

self.reset_button = wx.Button(panel, -1, "Reset")
vbox.Add(self.reset_button, 0, wx.ALIGN_CENTRE)
self.reset_button.Bind(wx.EVT_BUTTON,self.OnClicked)

# add Nvidia logo
imageFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'nvidia-logo.png')
png = wx.Image(imageFile, wx.BITMAP_TYPE_ANY)
png = png.Scale(200, 40, wx.IMAGE_QUALITY_HIGH).ConvertToBitmap()
im = wx.StaticBitmap(panel, -1, png)
vbox.Add(im, 0, wx.ALL, 5)

hbox.Add(vbox, 0, wx.ALIGN_RIGHT)
panel.SetSizer(hbox)

Expand All @@ -221,6 +237,11 @@ def __init__(self, parent=None, grid_size=640, attributes=[]):

self.Bind(DISPLAY_GRID_EVT, self.OnDisplayCell)

def OnClicked(self, event):
self.speed_slider.SetValue(5)
for s in self.attribute_sliders:
s.SetValue(0)

def OnQuit(self,event):
self.Close(True)

Expand Down Expand Up @@ -252,6 +273,9 @@ def DisplayCell(self, array):
evt = MyEvent(myEVT, -1, array)
wx.PostEvent(self.frame, evt)

def GetGender(self):
return self.frame.gender_box.GetStringSelection()

def GetSpeed(self):
return self.frame.speed_slider.GetValue()

Expand Down
Binary file added digits/tools/tensorflow/nvidia-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.