MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / log_txt_as_img

Function log_txt_as_img

sat/sgm/util.py:156–181  ·  view source on GitHub ↗
(wh, xc, size=10)

Source from the content-addressed store, hash-verified

154
155
156def log_txt_as_img(wh, xc, size=10):
157 # wh a tuple of (width, height)
158 # xc a list of captions to plot
159 b = len(xc)
160 txts = list()
161 for bi in range(b):
162 txt = Image.new("RGB", wh, color="white")
163 draw = ImageDraw.Draw(txt)
164 font = ImageFont.truetype("data/DejaVuSans.ttf", size=size)
165 nc = int(40 * (wh[0] / 256))
166 if isinstance(xc[bi], list):
167 text_seq = xc[bi][0]
168 else:
169 text_seq = xc[bi]
170 lines = "\n".join(text_seq[start : start + nc] for start in range(0, len(text_seq), nc))
171
172 try:
173 draw.text((0, 0), lines, fill="black", font=font)
174 except UnicodeEncodeError:
175 print("Cant encode string for logging. Skipping.")
176
177 txt = np.array(txt).transpose(2, 0, 1) / 127.5 - 1.0
178 txts.append(txt)
179 txts = np.stack(txts)
180 txts = torch.tensor(txts)
181 return txts
182
183
184def partialclass(cls, *args, **kwargs):

Callers 1

log_conditioningsMethod · 0.90

Calls 2

appendMethod · 0.80
printFunction · 0.50

Tested by

no test coverage detected