RoboTwin_image/envs/utils/save_file.py
2025-07-02 03:13:07 +00:00

27 lines
625 B
Python

import numpy as np
from PIL import Image, ImageColor
import json
import os
import pickle
def ensure_dir(file_path):
directory = os.path.dirname(file_path)
if not os.path.exists(directory):
os.makedirs(directory)
def save_img(save_path, img_file):
img = Image.fromarray(img_file)
ensure_dir(save_path)
img.save(save_path)
def save_json(save_path, json_file):
ensure_dir(save_path)
with open(save_path, 'w') as f:
json.dump(json_file, f, indent=4)
def save_pkl(save_path,dic_file):
ensure_dir(save_path)
with open(save_path, 'wb') as f:
pickle.dump(dic_file, f)