<jupyter_start><jupyter_text>Verify dataset generated by rmpe_dataset_transformer<jupyter_code>import json
import cv2
import numpy as np
import matplotlib.pyplot as plt
import os,glob
def load(file):
    with open(file,encoding='utf-8') as infile:
        inside=json.load(infile)
    return inside
def save(file,obj):
    with open(file, 'w') as outfile:
        json.dump(obj, outfile)
import math
def rotate(xy, theta):
    # https://en.wikipedia.org/wiki/Rotation_matrix#In_two_dimensions
    cos_theta, sin_theta = math.cos(theta), math.sin(theta)

    return (
        xy[0] * cos_theta - xy[1] * sin_theta,
        xy[0] * sin_theta + xy[1] * cos_theta
    )
def translate(xy, offset):
    return xy[0] + offset[0], xy[1] + offset[1]

def tag_angle(x1,y1,x2,y2):
    #angle in radians
    dx = x1-x2
    dy = y1-y2 
    norm = np.sqrt(dx**2+dy**2)
    up = [dx/norm,dy/norm]
    angle= np.arctan2(up[0], -up[1])#/np.pi*180    
    return angle
def bbox(head,abdomen,size=[90,150]):
    rectangle=[(-size[0],size[1]),(-size[0],-size[1]),(size[0],-size[1]),(size[0],size[1])]

    theta=tag_angle(head[0],head[1],abdomen[0],abdomen[1])
    offset=((head[0]+abdomen[0])/2.,(abdomen[1]+head[1])/2.)

    return [translate(rotate(xy, theta), offset) for xy in rectangle]
bees = load('../data/raw/monkey/dataset_raw/train_monkey.json')
shrimp = load('../data/raw/shrimp/Shrimp_annotations.json')<jupyter_output><empty_output><jupyter_text>Verify data generator client<jupyter_code>%matplotlib inline
import matplotlib.pyplot  as plt
import cv2
import sys
sys.path.append('..')
import beepose.train.ds_client_generator as ds
client = ds.DataGeneratorClient(port=5555, host="localhost", hwm=1, batch_size=10)
client.restart()
batch_index = 0
x,y = next(client.gen())
x[0].shape
x[1].shape
print(x[0].shape)
print(x[1].shape)
print(x[2].shape)

print(y[0].shape)
print(y[1].shape)
print(y[2].shape)
print(y[3].shape)
print(y[4].shape)
print(y[5].shape)
print(y[6].shape)
print(y[7].shape)
print(y[8].shape)
print(y[9].shape)
print(y[10].shape)
print(y[11].shape)
x[0].shape<jupyter_output><empty_output><jupyter_text>Show orig image<jupyter_code>plt.rcParams['figure.figsize'] = 5, 5
#x,y = next(client.gen())
dta_img = x[0][batch_index,:,:,:]
plt.imshow(dta_img[:,:,[2,1,0]])
np.min(dta_img)<jupyter_output><empty_output><jupyter_text>Show orig img + mask<jupyter_code>dta_img = x[0][batch_index,:,:,:]
plt.imshow(dta_img[:,:,[2,1,0]])

mask_img = x[1][batch_index,:,:,:]
mask_img = cv2.resize(mask_img[:,:, 0], (0,0), fx=8, fy=8, interpolation=cv2.INTER_CUBIC)


plt.imshow(mask_img * 255, cmap='gray', alpha=.5)
import numpy as np
np.min(x[2][batch_index,:,:,:])<jupyter_output><empty_output><jupyter_text>Show heatmap<jupyter_code>batch_index =0
body_part = 3

x,y = next(client.gen())
dta_img = x[0][batch_index,:,:,:]
plt.imshow(dta_img[:,:,[2,1,0]])

heatmap = cv2.resize(y[1][batch_index, :, :, body_part], (0,0), fx=8, fy=8, interpolation=cv2.INTER_CUBIC)

plt.imshow(dta_img[:,:,[2,1,0]])
plt.imshow(heatmap[:,:], alpha=.5)
heatmap.dtype<jupyter_output><empty_output><jupyter_text>Show PAF<jupyter_code>batch_index = 0
paf_idx = 0
x,y = next(client.gen())
dta_img = x[0][batch_index,:,:,:]
plt.imshow(dta_img[:,:,[2,1,0]])

paf = cv2.resize(y[2][batch_index, :, :, paf_idx], (0,0), fx=8, fy=8, interpolation=cv2.INTER_CUBIC)

plt.imshow(dta_img[:,:,[2,1,0]])
plt.imshow(paf[:,:], alpha=.7)<jupyter_output><empty_output><jupyter_text>client.stop()<jupyter_code>val_client = DataGeneratorClient(port=5555, host="localhost", hwm=160, batch_size=10)
val_client.start()
val_di = val_client.gen()
batch_index =0
body_part = 1
dta_img = x[0][batch_index,:,:,:]
plt.imshow(dta_img[:,:,[2,1,0]])

heatmap = cv2.resize(y[1][batch_index, :, :, body_part], (0,0), fx=8, fy=8, interpolation=cv2.INTER_CUBIC)

plt.imshow(dta_img[:,:,[2,1,0]])
plt.imshow(heatmap[:,:], alpha=.5)<jupyter_output><empty_output><jupyter_text>y<jupyter_code>U
import numpy as np
from numpy import ma
U =cv2.resize(y[2][batch_index, :, :, 1], (0,0), fx=8, fy=8, interpolation=cv2.INTER_CUBIC)
V =cv2.resize(y[2][batch_index, :, :, 2], (0,0), fx=8, fy=8, interpolation=cv2.INTER_CUBIC)
X, Y = np.meshgrid(np.arange(U.shape[1]), np.arange(U.shape[0]))
#M = np.zeros(U.shape, dtype='bool')
#M[U**2 + V**2 < 0.5 * 0.5] = True
#U = ma.masked_array(U, mask=M)
#V = ma.masked_array(V, mask=M)

# 1
plt.figure()
plt.imshow(dta_img[:,:,[2,1,0]])
s = 5
Q = plt.quiver(X[::s,::s], Y[::s,::s], U[::s,::s], V[::s,::s], 
               scale=10, headaxislength=1, alpha=.5, width=0.0001, color='r')

fig = plt.gcf()
fig.set_size_inches(20, 20)
from src.data.pose_augmenter import *
import src.data.pose_augmenter
import sys
sys.path.append('..')

train_di = client.gen()
x,y = next(train_di)
len(x)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21128526645768025, 'fraction_numerical': 0.04242424242424243, 'mean_word_length': 6.186186186186186, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '289064', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2235, 'n_tokens_neox': 2158, 'n_words': 311, 'path': 'notebooks/inspect_dataset.ipynb', 'repo_name': 'dreamstorm25/beepose', 'size': '4785'}