Code Monkey home page Code Monkey logo

logan's Introduction

LoGAN user guide

This README will explain how to set-up and run the code for LoGAN: Generating Logos with a Generative Adversarial Neural Network Conditioned on Colour.

Getting the data and Training the model

  • Download LLD-Icons PNG files from: https://data.vision.ee.ethz.ch/sagea/lld/data/LLD-icon_PNG.zip
  • Set up a Python 3.5 environment with the packages mentioned below
  • Run get_colors.py (change the PATH variable to main directory)
    • In your current directory a file 'colors.csv' will be created with 3 columns (name of file, top 3 colors in file, amount of each of the top 3 colors) - Run change_colors_to_words.py (change path variable to main directory)
    • A one hot encoding of the colors extracetd previously will be created in the data folder - Change the path of the data and the one-hot-encoding csv on read_images.py - Run main.py

Overview of the files

File Function Parameters
get_colors.py Uses the logos to find RGB centroids for the KMeans clusters for each image (output:colors.csv) PATH - of working directory, TRAINING - true in training mode, VERBOSE - wether to print details
change_colors_to_words.py Uses colors.csv to create a one-hot-encoding for the labels (output:one_hot_encoding_color_icon.csv) PATH - of working directory, TRAINING - true in training mode, VERBOSE - wether to print details
acgan.py The class of the ACGAN
main.py The main class. Use this to start training the model and tweak the parameters. gan_type - only ACWGANGP, dataset - only available dataset lld, epoch - number of epochs to train, batch_size - size of batch to train, z_dim - dimension of noise vector, checkpoint_dir-to save checkpoint, result_dir-directory to save results, log_dir-tensorboard log directory
ops.py Defines the layers.
utils.py Defines useful functions.
read_images.py Defines two methods, to read images, and labels in one hot encoding format. Data_PATH, label_csv_PATH, IMAGE_SIZE - size of the images, CATEGORIES - classes, BATCH_SIZE - size of batch, VERBOSE - wether to print details
make_confusion_matrix.py Used to get the confusion matrix to get the results as in paper.

Necessary packages

Python 3.5 tensorflow (1.4+) numpy (1.13.1 and 1.14.1) PIL (pillow) (5.1.0) pandas (0.20.3) webcolors (1.8.1) scikit-learn (0.19.0) matplotlib (2.12.2) cv2 (opencv-python) (3.4.0.12)

logan's People

Contributors

ajki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

logan's Issues

IndexError: list index out of range

Hello, I had a

(venv) ip-192-168-1-103:LoGAN loretoparisi$ python change_colors_to_words.py

data
Progress: 100.00%
Format change complete.
Progress: 100.00%
Color word match complete.
Traceback (most recent call last):
  File "change_colors_to_words.py", line 202, in <module>
    word_most.append(color_word_sorted[2])
IndexError: list index out of range
(venv) ip-192-168-1-103:LoGAN loretoparisi$ python change_colors_to_words.py

So I have tried to fix it adding a guard on list size

for img in colors.index:
        #sort according to amount of color
        color_word_sorted=[x for _,x in sorted(zip(colors['amount color'][img],colors['color word'][img]))]
        if len(color_word_sorted) > 2:
            word_least.append(color_word_sorted[0])
            word_middle.append(color_word_sorted[1])
            word_most.append(color_word_sorted[2])
            #sort according to amount of color
            color_word_compact_sorted = [x for _,x in sorted(zip(colors['amount color'][img],colors['color word compact'][img]))]
            compact_least.append(color_word_compact_sorted[0])
            compact_middle.append(color_word_compact_sorted[1])
            compact_most.append(color_word_compact_sorted[2])        
        
    colors.drop(colors.columns[[2,3]], axis=1, inplace= True )
    colors['word least'] = word_least
    colors['word middle'] = word_middle
    colors['word most'] = word_most
    colors['compact least'] = compact_least
    colors['compact middle'] = compact_middle
    colors['compact most'] = compact_most

problem is that now I get a wrong DataFrame size:

Progress: 100.00%
Format change complete.
Progress: 100.00%
Color word match complete.
Traceback (most recent call last):
  File "change_colors_to_words.py", line 211, in <module>
    colors['word least'] = word_least
  File "/Users/loretoparisi/Documents/Projects/AI/LoGAN/venv/lib/python3.6/site-packages/pandas/core/frame.py", line 3119, in __setitem__
    self._set_item(key, value)
  File "/Users/loretoparisi/Documents/Projects/AI/LoGAN/venv/lib/python3.6/site-packages/pandas/core/frame.py", line 3194, in _set_item
    value = self._sanitize_column(key, value)
  File "/Users/loretoparisi/Documents/Projects/AI/LoGAN/venv/lib/python3.6/site-packages/pandas/core/frame.py", line 3391, in _sanitize_column
    value = _sanitize_index(value, self.index, copy=False)
  File "/Users/loretoparisi/Documents/Projects/AI/LoGAN/venv/lib/python3.6/site-packages/pandas/core/series.py", line 4001, in _sanitize_index
    raise ValueError('Length of values does not match length of ' 'index')
ValueError: Length of values does not match length of index

May I have to add zero values in the else of that guard?

Thank you.

read.image.py中images.append(['(image_name)', im])===>int换为字符串

def read_images_from(path=Data_PATH):
images = []
png_files_path = glob.glob(os.path.join(path, '*.[pP][nN][gG]')) # extract all png files

if VERBOSE:
    print("Reading images ...")

cnt=0
for filename in png_files_path:
    im = Image.open(filename)

    im = np.asarray(im, np.uint8)
    # get image name, not path
    image_name = filename.split('\\')[-1].split('.')[0]
    #images.append([int(image_name), im])
    **images.append(['(image_name)', im])**
    #images.append(im)

    cnt+=1
    if VERBOSE:
        sys.stdout.write("Progress loading images: {:.2%}\r".format(cnt/485377))
        sys.stdout.flush()

images = sorted(images, key=lambda image: image[0])

images_only = [np.asarray(image[1], np.uint8) for image in images]
images_only = np.array(images_only)

return images_only

image with only two colors

For the images with only two colors, such as 001904.png and 002678.png, the following lines in change_colors_to_words.py may not work. This is because len(color_word_sorted)==2

word_least.append(color_word_sorted[0])
word_middle.append(color_word_sorted[1])
word_most.append(color_word_sorted[2])

Is this need to change to:

word_least.append(color_word_sorted[0])
if len(color_word_sorted)>=2:
    word_middle.append(color_word_sorted[1])
    if len(color_word_sorted)>=3:
        word_most.append(color_word_sorted[2])
    else:
        word_most.append(color_word_sorted[1])
else:
    word_middle.append(color_word_sorted[0])
    word_middle.append(color_word_sorted[0])

License?

Is there a license for this work? Can it be re-used?

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.