Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ __pycache__/

# C extensions
*.so

/custom_data_set/*.npy
/custom_data_set/*.txt
/hand_gen_37_torch/
/data/*.json
/logs/
# Distribution / packaging
.Python
build/
Expand Down
4 changes: 2 additions & 2 deletions app/priming.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def generate_handwriting(
bias=10.0,
):
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
data_path = os.path.join(app_path, "../data/")
model_path = os.path.join(app_path, "../results/synthesis/best_model_synthesis.pt")
data_path = os.path.join(app_path, "../custom_data_set/")
model_path = os.path.join(app_path, "/media/hassan/New Volume1/Remote_work_Research_work/Handwriting-synthesis/logs/best_model_own_datasynthesis.pt")
# seed = 194
# print("seed:",seed)
# torch.manual_seed(seed)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions custom_data_set/prepare_data_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import numpy as np
import json

# Load your JSON data
def convert_json_to_repo_format(json_file_path, output_npy_path, output_txt_path):
# Load JSON data
with open(json_file_path, 'r') as f:
data = json.load(f)

# Initialize lists to store processed data
all_strokes = []
all_prompts = []

# Calculate mean and std for normalization
all_x = []
all_y = []

# First pass to collect all x, y coordinates for normalization
for entry in data:
stroke_data = entry['stroke_data']
for stroke in stroke_data:
for point in stroke:
all_x.append(point['x'])
all_y.append(point['y'])

# Calculate mean and std
x_mean = np.mean(all_x)
y_mean = np.mean(all_y)
x_std = np.std(all_x)
y_std = np.std(all_y)

print(f"X mean: {x_mean}, X std: {x_std}")
print(f"Y mean: {y_mean}, Y std: {y_std}")

# Second pass to process the data
for entry in data:
prompt_text = entry['prompt_text']
stroke_data = entry['stroke_data']

# Convert stroke data to the required format
formatted_strokes = []

for stroke in stroke_data:
for i, point in enumerate(stroke):
# Normalize x and y
x_norm = (point['x'] - x_mean) / x_std
y_norm = (point['y'] - y_mean) / y_std

# Last point in a stroke gets 1, others get 0
end_of_stroke = 1 if i == len(stroke) - 1 else 0

formatted_strokes.append([end_of_stroke, x_norm, y_norm])

# Convert to numpy array
formatted_strokes = np.array(formatted_strokes)

all_strokes.append(formatted_strokes)
all_prompts.append(prompt_text)

# Save the processed data
# Convert all_strokes to a numpy array with dtype=object since each stroke array has different shape
all_strokes_array = np.array(all_strokes, dtype=object)
np.save(output_npy_path, all_strokes_array)

# Write prompts to text file
with open(output_txt_path, 'w') as f:
f.write('\n'.join(all_prompts))

print(f"Saved {len(all_strokes)} entries to {output_npy_path} and {output_txt_path}")

# Print sample information
if len(all_strokes) > 0:
print(f"Shape of the first entry: {all_strokes[0].shape}")
print(f"Sample data from first entry:")
print(all_strokes[0][:3]) # First 3 points
print(all_strokes[0][-3:]) # Last 3 points

# Usage
convert_json_to_repo_format(
'/media/hassan/New Volume1/Remote_work_Research_work/Handwriting-synthesis/data/hand_1000_data.json',
'strokes_data.npy',
'sentences_data.txt'
)
189 changes: 189 additions & 0 deletions eda_exp.ipynb

Large diffs are not rendered by default.

255 changes: 236 additions & 19 deletions notebooks/arr_to_svg.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sample.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def argparser():
parser.add_argument("--lr", type=float, default=0.001)
parser.add_argument("--patience", type=int, default=15)
parser.add_argument("--model_type", type=str, default="prediction")
parser.add_argument("--data_path", type=str, default="./data/")
parser.add_argument("--data_path", type=str, default="./custom_data_set/")
parser.add_argument("--save_path", type=str, default="./logs/")
parser.add_argument("--text_req", action="store_true")
parser.add_argument("--data_aug", action="store_true")
Expand Down Expand Up @@ -163,7 +163,7 @@ def train(
model_type,
save_path,
):
model_path = save_path + "best_model_" + model_type + ".pt"
model_path = save_path + "best_model_own_data" + model_type + ".pt"
model = model.to(device)

optimizer = optim.Adam(model.parameters(), lr=lr)
Expand Down