Python json.encoder.FLOAT_REPR Examples
The following are 30
code examples of json.encoder.FLOAT_REPR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
json.encoder
, or try the search function
.
Example #1
Source File: json_utils.py From vehicle_counting_tensorflow with MIT License | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #2
Source File: json_utils.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #3
Source File: json_utils.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #4
Source File: json_utils.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #5
Source File: json_utils.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #6
Source File: json_utils.py From MAX-Object-Detector with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #7
Source File: json_utils.py From MAX-Object-Detector with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #8
Source File: json_utils.py From AniSeg with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #9
Source File: json_utils.py From AniSeg with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #10
Source File: json_utils.py From Elphas with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #11
Source File: json_utils.py From Elphas with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #12
Source File: json_utils.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #13
Source File: json_utils.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #14
Source File: json_utils.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #15
Source File: json_utils.py From BMW-TensorFlow-Training-GUI with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #16
Source File: json_utils.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #17
Source File: json_utils.py From vehicle_counting_tensorflow with MIT License | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #18
Source File: json_utils.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #19
Source File: json_utils.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #20
Source File: json_utils.py From Person-Detection-and-Tracking with MIT License | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #21
Source File: json_utils.py From Person-Detection-and-Tracking with MIT License | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #22
Source File: json_utils.py From Traffic-Rule-Violation-Detection-System with MIT License | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #23
Source File: json_utils.py From Traffic-Rule-Violation-Detection-System with MIT License | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #24
Source File: json_utils.py From Gun-Detector with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #25
Source File: json_utils.py From Gun-Detector with Apache License 2.0 | 6 votes |
def Dumps(obj, float_digits=-1, **params): """Wrapper of json.dumps that allows specifying the float precision used. Args: obj: The object to dump. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. Returns: output: JSON string representation of obj. """ original_encoder = encoder.FLOAT_REPR original_c_make_encoder = encoder.c_make_encoder if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) encoder.c_make_encoder = None try: output = json.dumps(obj, **params) finally: encoder.FLOAT_REPR = original_encoder encoder.c_make_encoder = original_c_make_encoder return output
Example #26
Source File: json_utils.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def Dump(obj, fid, float_digits=-1, **params): """Wrapper of json.dump that allows specifying the float precision used. Args: obj: The object to dump. fid: The file id to write to. float_digits: The number of digits of precision when writing floats out. **params: Additional parameters to pass to json.dumps. """ original_encoder = encoder.FLOAT_REPR if float_digits >= 0: encoder.FLOAT_REPR = lambda o: format(o, '.%df' % float_digits) try: json.dump(obj, fid, **params) finally: encoder.FLOAT_REPR = original_encoder
Example #27
Source File: ScatterPlot1.py From termite-data-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, request, response, corpus_db, bow_db, lda_db): super(ScatterPlot1, self).__init__(request, response) JsonEncoder.FLOAT_REPR = lambda number : format(number, '.4g') self.corpusDB = corpus_db self.bowDB = bow_db self.ldaDB = lda_db self.bow = bow_db.db self.db = lda_db.db
Example #28
Source File: eval_utils.py From NeuralBabyTalk with MIT License | 5 votes |
def language_eval(dataset, preds, model_id, split): import sys sys.path.append("coco-caption") annFile = 'coco-caption/annotations/captions_val2014.json' from pycocotools.coco import COCO from pycocoevalcap.eval import COCOEvalCap encoder.FLOAT_REPR = lambda o: format(o, '.3f') if not os.path.isdir('eval_results'): os.mkdir('eval_results') cache_path = os.path.join('eval_results/', model_id + '_' + split + '.json') coco = COCO(annFile) valids = coco.getImgIds() # filter results to only those in MSCOCO validation set (will be about a third) preds_filt = [p for p in preds if p['image_id'] in valids] print('using %d/%d predictions' % (len(preds_filt), len(preds))) json.dump(preds_filt, open(cache_path, 'w')) # serialize to temporary json file. Sigh, COCO API... cocoRes = coco.loadRes(cache_path) cocoEval = COCOEvalCap(coco, cocoRes) cocoEval.params['image_id'] = cocoRes.getImgIds() cocoEval.evaluate() # create output dictionary out = {} for metric, score in cocoEval.eval.items(): out[metric] = score imgToEval = cocoEval.imgToEval for p in preds_filt: image_id, caption = p['image_id'], p['caption'] imgToEval[image_id]['caption'] = caption with open(cache_path, 'w') as outfile: json.dump({'overall': out, 'imgToEval': imgToEval}, outfile) return out
Example #29
Source File: GroupInBox.py From termite-data-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, request, response, corpus_db, bow_db, lda_db): super(GroupInBox, self).__init__(request, response) JsonEncoder.FLOAT_REPR = lambda number : format(number, '.4g') self.corpusDB = corpus_db self.bowDB = bow_db self.ldaDB = lda_db self.bow = bow_db.db self.db = lda_db.db ################################################################################
Example #30
Source File: ScatterPlot1.py From termite-data-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, request, response, corpus_db, bow_db, lda_db): super(ScatterPlot1, self).__init__(request, response) JsonEncoder.FLOAT_REPR = lambda number : format(number, '.4g') self.corpusDB = corpus_db self.bowDB = bow_db self.ldaDB = lda_db self.bow = bow_db.db self.db = lda_db.db