Skip to content

Instantly share code, notes, and snippets.

@bhpfelix
bhpfelix / convert.py
Last active October 27, 2020 04:10
Code snippet for porting TensorFlow trained model to PyTorch
import numpy as np
from PIL import Image
np.random.seed(2)
import torchvision
import torch
# torch.manual_seed(0)
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
import tensorflow as tf
@omoindrot
omoindrot / tensorflow_finetune.py
Last active February 25, 2024 15:00
Example TensorFlow script for fine-tuning a VGG model (uses tf.contrib.data)
"""
Example TensorFlow script for finetuning a VGG model on your own data.
Uses tf.contrib.data module which is in release v1.2
Based on PyTorch example from Justin Johnson
(https://gist.github.com/jcjohnson/6e41e8512c17eae5da50aebef3378a4c)
Required packages: tensorflow (v1.2)
Download the weights trained on ImageNet for VGG:
```
wget http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz
import argparse
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.utils.data import DataLoader
import torchvision
import torchvision.transforms as T
from torchvision.datasets import ImageFolder