Giter Club home page Giter Club logo

Comments (3)

adorsho avatar adorsho commented on September 26, 2024

hello @MeteoRex11 did you solve this problem ? I am facing the same problem, please help me

from t2f.

harbarex avatar harbarex commented on September 26, 2024

You would need to store text in torch file format, with text embeddings already in them. This is a very tedious process, hence I did not make a script for it

from t2f.

shiv6891 avatar shiv6891 commented on September 26, 2024

I got it working after few cpu specific modifications for my laptop, using below:

Referred from: An IPYNB
Note: Depending upon PT version, few minor changes might be required

After importing your condition augmentor, text encoder and gan generator...

import pickle
file_name = 'path/to/your/.pkl'
obj = None
# obj = pickle.loads(open(file_name, 'rb').read())
with open(file_name, "rb") as pick:
    obj = pickle.loads(pick.read())

max_caption_len = 100
in_str = input('Enter your caption : ')
in_str_tok = in_str.replace('_', ' ').split()
in_ind_list = [obj['rev_vocab'][in_str.strip()] for in_str in in_str_tok if in_str.strip() in obj['rev_vocab']]
caption = in_ind_list
full_str = []
for ind in caption:
    full_str.append(obj['vocab'][ind])
str_proc = filter('<pad>'.__ne__, full_str)
    
if len(caption) < max_caption_len:
    while len(caption) != max_caption_len:
        caption.append(obj['rev_vocab']["<pad>"])

elif len(caption) > max_caption_len:
    caption = caption[: max_caption_len]

fixed_captions = th.tensor([caption], dtype=th.long)
print("Text initialized!")

fixed_embeddings = text_encoder(fixed_captions)
fixed_embeddings = th.from_numpy(fixed_embeddings.detach().cpu().data.numpy()).to(device)
fixed_c_not_hats, mus, _ = condition_augmenter(fixed_embeddings)
fixed_noise = th.zeros(len(fixed_captions), c_pro_gan.latent_size - fixed_c_not_hats.shape[-1]).to(device)
fixed_gan_input = th.cat((fixed_c_not_hats, fixed_noise), dim=-1)
print("Gan input prepared")

And then...

import matplotlib.pyplot as plt
%matplotlib inline
create_grid(
    samples=c_pro_gan.gen(
        fixed_gan_input,
        4,
        1.0
    ),
    scale_factor=1,
    img_file='output.png')

img = plt.imread('output.png')
plt.figure()
plt.imshow(img)

from t2f.

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.