Skip to content

Instantly share code, notes, and snippets.

View innat's full-sized avatar
:octocat:
Working from home

Mohammed Innat innat

:octocat:
Working from home
View GitHub Profile

AI Agent Instruction: Integrating ag Command for Antigravity

Scenario & Objective

The user has installed a tool called Antigravity (which acts similar to VS Code or Cursor). The underlying CLI command is antigravity (or antigravity.cmd on Windows). The goal is to map ag . so that it seamlessly opens the current directory in Antigravity across three environments:

  1. Windows Command Prompt (cmd.exe)
  2. Windows PowerShell (powershell.exe / pwsh)
  3. Windows Subsystem for Linux (WSL / Bash) When a user types ag ., it should invoke antigravity . automatically, exactly like how code . or cursor . works.

Instructions for Implemention (For AI Agents)

@innat
innat / AdaptivePooling.py
Created November 1, 2025 18:03
adaptive pooling in keras 3
# ATTENTION: In training, this will work on torch and tensorflow backend, not in jax.
import os
os.environ["KERAS_BACKEND"] = "torch" # tensorflow, torch, jax
import keras
from keras import layers, ops
from medicai.utils.swi_utils import ensure_tuple_rep
@innat
innat / [TensorFlow] Depth Interpolation.py
Last active March 11, 2025 08:12
Depth interpolation for 3D volume
import tensorflow as tf
def linear_interpolation(volume, target_depth, depth_axis=0):
# Get the original depth size along the specified axis
original_depth = tf.shape(volume)[depth_axis]
# Generate floating-point indices for the target depth
indices = tf.linspace(0.0, tf.cast(original_depth - 1, tf.float32), target_depth)
# Split indices into integer and fractional parts

Preface

The following notes are generated from ChatGPT and modified while dumping here.

GPU Driver:

  • The GPU driver acts as an interface between your operating system and the hardware.
  • It ensures your OS can communicate with and utilize the GPU for tasks.

CUDA Toolkit:

  • The CUDA Toolkit is required for developing and running GPU-accelerated applications.
import tensorflow as tf
from tensorflow.keras import layers
H_AXIS = -3
W_AXIS = -2
class RandomCutout(layers.Layer):
"""Randomly cut out rectangles from images and fill them.
Args:

Note

While writing a video data to tfrecord format, the output tfrecord file size would be much larger than the original video file. For quick demonstration purpose, some may use frame step to encode the frame to keep the overal size minimal. But in actual case (research or project) all frame should be considered while encoding to tfrecord. By doing so, while using the tfrecord in the training time, we can sample frames with different indices. Check this discussion. The following code is tested in tf 2.12.

video data layout

Let's say, we have a video data set in the following format.

@innat
innat / [Torch2Keras] Multi Head Self Attention.md
Last active September 28, 2023 19:44
torch 2 tf mha weight porting

About: A simple demonstration to translate multihead self attention from PyTorch to Keras.

Multi-Head Self Attention

import torch
import torch.nn as nn

class TorchAttentionModel(nn.Module):
# Ref: https://gist.github.com/Rocketknight1/efc47242914788def0144b341b1ad638
import math
import tensorflow as tf
from tensorflow.keras import layers
class TFAdaptiveAveragePooling(layers.Layer):
def __init__(self, output_size, **kwargs):
super().__init__(**kwargs)
if not isinstance(output_size, (list, tuple)):
from typing import Tuple
import tensorflow as tf
from keras import layers
def uniform_temporal_subsample(x, num_samples, temporal_dim=-4):
"""
Uniformly subsamples num_samples indices from the temporal dimension of the video.
When num_samples is larger than the size of temporal dimension of the video, it
will sample frames based on nearest neighbor interpolation.
# ref. https://www.tensorflow.org/tutorials/video/video_classification

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

class Conv2Plus1D(keras.Model):
    def __init__(self, filters, kernel_size, padding):
        """A sequence of convolutional layers