cifr-pytorch / utils /data_utils.py
birdortyedi
Add application file
2a92dc2
raw
history blame contribute delete
621 Bytes
import json
def linear_scaling(x):
return (x * 255.) / 127.5 - 1.
def linear_unscaling(x):
return (x + 1.) * 127.5 / 255.
def read_json(path):
"""
:param path (str or os.Path): JSON file path.
:return: (Dict): the data in the JSON file.
"""
with open(path) as f:
data = json.load(f)
return data
def write_json(path, datagroup):
"""
:param path (str or os.Path): File path for the output JSON file.
:param datagroup (Dict): The data which should be dump to the JSON file.
:return: void.
"""
with open(path, "w+") as f:
json.dump(datagroup, f)