Skip to content

Instantly share code, notes, and snippets.

View luuil's full-sized avatar
🎯
Focusing

luuil

🎯
Focusing
View GitHub Profile
@luuil
luuil / ollama_model_download.py
Created February 8, 2025 08:26
Used with the `ollama-model-direct-download` software, you can download ollama models with one click.
"""
Manually download the ollama model
1. You need a software (Linux only): https://github.com/amirrezaDev1378/ollama-model-direct-download
2. Use the software to get the download links of the model, it will output 6 links. (If the file downloaded from the release page is not available, you need to install the Go environment and compile it yourself)
3. You can manually download them, or use this script to download all at once.
"""
import subprocess
import re
import json
import requests
@luuil
luuil / hfdown.py
Last active March 20, 2025 11:18
hfdown: Download file/repo from url of huggingface
"""
# @ Author: Lu Liu
# @ Create Time: 2024-12-05 14:28:43
# @ Modified by: Lu Liu
# @ Modified time: 2025-03-20 18:56:59
# @ Description: 从huggingface下载
# - 整个repo
# - 单个文件
# huya海聪平台外网加速器 https://ai.huya.com/docs/QA/common.html#%E9%80%9A%E7%94%A8%E5%A4%96%E7%BD%91%E4%B8%8B%E8%BD%BD%E5%8A%A0%E9%80%9F%E5%99%A8
@luuil
luuil / RunTime.py
Created March 1, 2024 02:32
Statistical Time Consumption
'''
# @ Author: Lu Liu
# @ Create Time: 2024-02-28 18:02:05
# @ Modified by: Lu Liu
# @ Modified time: 2024-02-28 18:08:28
# @ Description:
'''
import time
@luuil
luuil / TFRecordCreator.py
Last active November 18, 2021 14:32
TFRecord creation and inspection, such as records count and visualize etc.
import os
import tensorflow as tf
import numpy as np
from PIL import Image
import io
def bytes_feature(value):
"""Returns a bytes_list from a string / byte."""
if isinstance(value, type(tf.constant(0))):
@luuil
luuil / topk.py
Last active November 9, 2021 04:02
Find k largest or smallest(reverse is True) elements from stream data using built-in sorted function.
import numpy as np
class TopK(object):
def __init__(self, k, key=None, reverse=False) -> None:
""" Find k largest or smallest(reverse is True) elements from stream data.
"""
super(TopK, self).__init__()
self._heap = list()
self._k = k
@luuil
luuil / benchmark.py
Last active October 25, 2022 06:17
monitor system status, such as usage of cpu, memory etc.
import os
import time
import subprocess
import shlex
import numpy as np
def run_process(tmpl, *args, **kwargs):
_args = args
cmd = tmpl.format(**kwargs)
@luuil
luuil / videos_grid.py
Last active July 4, 2024 02:12
Merging multiple videos/images/empty_frames into one grid video by opencv, PIL and numpy
import cv2
import os
import numpy as np
from PIL import Image, ImageFont, ImageDraw
from typing import Tuple, Optional, Union, List
from dataclasses import dataclass, InitVar
import sys
from pathlib import Path
from enum import Enum
import logging
@luuil
luuil / describe_tf_graph.py
Created November 6, 2019 08:50
show information in tensorflow graph def
def describe_graph(graph_def, show_nodes=False):
from collections import Counter
c = Counter(map(lambda n: n.op, graph_def.node))
print(c)
print('Input Nodes: {}'.format([node.name for node in graph_def.node if node.op == 'Placeholder']))
output_nodes = [node.name for node in graph_def.node if (
'predictions' in node.name or 'softmax' in node.name or 'concat' in node.name)]
print(f'Output Nodes: {output_nodes}')
import cv2
import os
class ExtractFromVideo(object):
def __init__(self, path, frame_range=None, debug=False):
assert os.path.exists(path)
self._p = path
self._vc = cv2.VideoCapture(self._p)
@luuil
luuil / freeze_graph.py
Created June 5, 2018 06:57
freeze tensorflow checkpoint to pb
def freeze_graph(model_dir, output_node_names):
"""Extract the sub graph defined by the output nodes and convert
all its variables into constant
Args:
model_dir: the root folder containing the checkpoint state file
output_node_names: a string, containing all the output node's names,
comma separated
"""
from os.path import join
import tensorflow as tf