Código
Browse filescreador de imagen
- código de modelo +19 -0
código de modelo
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
+
|
4 |
+
class TextToImageGenerator(torch.nn.Module):
|
5 |
+
def __init__(self, model_name="gpt2"):
|
6 |
+
super(TextToImageGenerator, self).__init__()
|
7 |
+
self.tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
8 |
+
self.gpt2 = GPT2LMHeadModel.from_pretrained(model_name)
|
9 |
+
|
10 |
+
def forward(self, input_text):
|
11 |
+
input_ids = self.tokenizer(input_text, return_tensors="pt")["input_ids"]
|
12 |
+
output = self.gpt2(input_ids, return_dict=True)
|
13 |
+
return output.logits
|
14 |
+
|
15 |
+
# Instanciar el modelo
|
16 |
+
model = TextToImageGenerator()
|
17 |
+
|
18 |
+
# Imprimir la arquitectura del modelo
|
19 |
+
print(model)
|