text
stringlengths
1
93.6k
img_size = proc_parm['img_size'][0]
# undo_scale = np.array(proc_parm['scale'])#1. / np.array(proc_parm['scale'])
undo_scale = img_size / constants.IMG_RES
cam_pos = cam[1:]
principal_pt = np.array([img_size, img_size]) / 2.
flength = constants.FOCAL_LENGTH
# tz = flength / (0.5 * constants.IMG_RES * cam_s)
tz = (2 * flength) / (constants.IMG_RES * cam[0] + 1e-9)
trans = np.hstack([cam_pos, tz])
vert_shifted = (verts + trans)
start_pt = proc_parm['start_pt']
final_principal_pt = principal_pt+ start_pt
cam_for_render = np.hstack(
[np.mean(flength * undo_scale), final_principal_pt[1], final_principal_pt[0]])
# This is in padded image.
# kp_original = (joints + proc_param['start_pt']) * undo_scale
# Subtract padding from joints.
# import ipdb; ipdb.set_trace()
# kp_original = (joints + proc_parm['start_pt']) * undo_scale
kp_original = (joints) * undo_scale + proc_parm['start_pt'][::-1]- (proc_parm['pad_x'][0],proc_parm['pad_y'][0])
return cam_for_render, vert_shifted, kp_original
# def get_original(proc_parm, verts, cam, joints):
#
# img_size = np.array(224)
# undo_scale = 1.
# print('und scale',undo_scale)
# # undo_scale = img_size / constants.IMG_RES
#
#
# cam_pos = cam[1:]
# principal_pt = np.array([img_size, img_size]) / 2.
# flength = 500
# # tz = flength / (0.5 * constants.IMG_RES * cam_s)
# tz = (2 * flength) / (constants.IMG_RES * cam[ 0] + 1e-9)
# trans = np.hstack([cam_pos, tz])
# vert_shifted = (verts + trans)
# print('img size', img_size)
# start_pt = proc_parm['start_pt']
# print('start pt', proc_parm['start_pt'] )
# print('principal pt', principal_pt)
# final_principal_pt = (principal_pt + start_pt)*undo_scale
# cam_for_render = np.hstack(
# [np.mean(flength * undo_scale), 1280/2,720/2])
#
# # This is in padded image.
# # kp_original = (joints + proc_param['start_pt']) * undo_scale
# # Subtract padding from joints.
# # import ipdb; ipdb.set_trace()
# # kp_original = (joints + proc_parm['start_pt']) * undo_scale
#
# kp_original = (joints ) * undo_scale + proc_parm['start_pt'][::-1] - (proc_parm['pad_x'][0],proc_parm['pad_y'][0])
#
# return cam_for_render, vert_shifted, kp_original
# <FILESEP>
import argparse
import datetime
import pandas as pd
from collections import defaultdict
import re
from pathlib import Path
GENERAL_WA_MULTI_SEARCH_PATTERN = r'\d?\d\/\d?\d\/\d?\d?\d\d, \d\d:\d\d:?\d?\d?\s?-? (.*?):(.*)'
LINE_SPLIT_DELIMITER = "\n"
def text_to_dictionary(text, prompt, response):
"""
We convert a whatsapp chat into a prompt and
response dataframe for the purposes of finetuning.
:param text:
:param prompt:
:param response:
:return:
"""
# convert from bytes to string
if isinstance(text, (bytes, bytearray)):
text = text.decode()
text_list = text.split('\n')[1:]
result_dict, count, prev_author = defaultdict(dict), 0, ''
for ix, line in enumerate(text_list):
search_pattern = re.search(GENERAL_WA_MULTI_SEARCH_PATTERN, line)
if search_pattern is not None:
author = search_pattern.group(1)
message = search_pattern.group(2).replace('"','')
else:
continue
if author == prompt:
if author == prev_author:
prev = result_dict[count]['prompt'][:-7]
result_dict[count]['prompt'] = f"{prev}. {message}\n\n###\n\n"
else:
count += 1
result_dict[count].update({'prompt': message + "\n\n###\n\n"})