Skip to content

Instantly share code, notes, and snippets.

@Loovelj
Loovelj / cal_tfrecord_num.py
Created September 1, 2020 07:16
tfrecord统计
# 该函数用于统计 TFRecord 文件中的样本数量(总数)
def total_sample(file_name):
sample_nums = 0
for record in tf.python_io.tf_record_iterator(file_name):
# for record in tf.data.TFRecordDataset(path)
sample_nums += 1
return sample_nums
@Loovelj
Loovelj / opencv_resize_mat_and_byte.py
Created June 2, 2020 08:56
opencv_resize_mat_and_byte.py
def resize_img_720p(img):
h,w = img.shape[:2]
new_h = max(h,w)
fx = 1280/new_h
resize_img = cv2.resize(img,(0, 0), fx = fx, fy = fx, interpolation = cv2.INTER_LINEAR)
img_encode = cv2.imencode('.jpg', resize_img)
str_encode = img_encode[1].tostring()
return resize_img, str_encode
import sys
import ruamel.yaml
yaml = ruamel.yaml.YAML()
# yaml.preserve_quotes = True
def up_yml(model_name):
with open('version.yaml') as fp:
data = yaml.load(fp)
data[1]["model_path"] = "test_model/" + model_name
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim([1, 10])
ax.set_ylim([1, 10])
@Loovelj
Loovelj / AlignCollate.py
Last active January 19, 2020 02:12
resize,长的变短,小的加pad变大
class AlignCollate(object):
def __init__(self, img_height=32, img_width=100):
self.img_height = img_height
self.img_width = img_width
self.transform = ResizeNormalize(img_width=self.img_width, img_height=self.img_height)
def __call__(self, batch):
images, labels = zip(*batch)
@Loovelj
Loovelj / rename_for_img.py
Created November 8, 2019 03:06
vegas重命名
import glob
import os
file_list = glob.glob('/data/data/huansuan/image/*')
for file in file_list:
new_name = file.replace('-','_')
os.rename(file,new_name)
print(file,new_name)
@Loovelj
Loovelj / resize_ratio_img.py
Created November 4, 2019 10:30
resize 图片
def resize_img_720p(img):
h,w = img.shape[:2]
new_h = max(h,w)
fx = 1280/new_h
resize_img = cv2.resize(img,(0, 0), fx = fx, fy = fx, interpolation = cv2.INTER_LINEAR)
return resize_img
@Loovelj
Loovelj / crnn_dataset.py
Created September 3, 2019 09:15
crnn_read_tfrecord
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import time
import json
import time as time
import tensorflow as tf
@Loovelj
Loovelj / ctc_decoder.py
Created August 13, 2019 06:36 — forked from awni/ctc_decoder.py
Example CTC Decoder in Python
"""
Author: Awni Hannun
This is an example CTC decoder written in Python. The code is
intended to be a simple example and is not designed to be
especially efficient.
The algorithm is a prefix beam search for a model trained
with the CTC loss function.
@Loovelj
Loovelj / requests_download_url.py
Created August 9, 2019 07:53
根据url下载数据
import requests
import os
with open(r'D:\liujun\20-31.txt','r',encoding='utf-8') as f:
file_list=f.readlines()
for file in file_list:
file=file.replace('\n','')
base_name=os.path.basename(file)
try:
url =file