Skip to content

Instantly share code, notes, and snippets.

@davecg
davecg / keras_1_to_2.py
Created April 9, 2017 18:01
Convert Keras 1 models to Keras 2
#!/usr/bin/env python3
'''
This will convert Keras 1 model weights and configurations
to their Keras 2 equivalent. Please note that all optimizer
configuration is ignored with this script and models will
need to be recompiled.
'''
import h5py
@davecg
davecg / fix_keras_model.py
Last active April 9, 2017 00:00 — forked from mgraczyk/fix_keras_model.py
Fix input_dtype errors in pre-2.0 keras model H5FS files
import h5py
import shutil
import json
import sys
def fix_weight_file(model_path):
with h5py.File(model_path, "r+") as out_h5:
v = out_h5.attrs.get("model_config")
config = json.loads(v)
@davecg
davecg / shape_index.py
Last active February 2, 2023 02:25
Calculate 3D shape index using PyTorch
import numpy as np
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torch.autograd import Variable
import torchvision
import torchvision.transforms as transforms
import numpy as np