Skip to content

Instantly share code, notes, and snippets.

View helinwang's full-sized avatar

Helin Wang helinwang

  • Bay Area
View GitHub Profile
@helinwang
helinwang / tf_decode_proto.py
Last active July 3, 2020 23:28
TensorFlow decode arbitrary Protobuf using tf.io.decode_proto and TFRecordDataset.
import tensorflow as tf
from google.protobuf.descriptor_pb2 import FileDescriptorSet
from google.protobuf.descriptor_pb2 import FileDescriptorProto
import baz_pb2
def decode(x):
proto = FileDescriptorProto()
@helinwang
helinwang / gist:f9ac4d3b8b927bdcd2a2b87a5ee7bb5e
Created December 3, 2020 18:38
Convert TF saved model to TensorBoard summary - works with unknown custom TF op
# Copyright 2019 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@helinwang
helinwang / tf_feature_columns.py
Last active October 31, 2021 01:27
A survey of TensorFlow feature columns
from tensorflow.keras import layers
import tensorflow as tf
import numpy as np
video_id = tf.feature_column.categorical_column_with_identity(
key="video_id", num_buckets=1000000, default_value=0
)
features = {
"video_id": tf.sparse.from_dense([[2, 85, 0, 0, 0], [33, 78, 2, 73, 1]]),
@helinwang
helinwang / gist:507b2fccbd04083854fbda4dcc88ccc6
Last active March 3, 2025 22:06
Make Nvidia GPU idle at around 9W instead of 20W
# save to /usr/local/bin/gpu-run
# exmaplea: gpu-run python train.py
# this makes Nvidia GPU idle at around 9W instead of 20W with the requirement of:
# 1. make sure no process using Nvidia GPU at idle, this requires setting up desktop manager to use iGPU
# 2. run this script
# 3. setup and run the systemd target at bottom of this file
# Function to restore low power state
function restore_power {
echo "Restoring low power state..."