GithubHelp home page GithubHelp logo

szagoruyko / functional-zoo Goto Github PK

View Code? Open in Web Editor NEW
584.0 584.0 93.0 1.01 MB

PyTorch and Tensorflow functional model definitions

Python 0.24% Jupyter Notebook 99.65% CMake 0.02% C++ 0.10%
pretrained-models pytorch tensorflow

functional-zoo's People

Contributors

dasguptar avatar edgarriba avatar sebastinsanty avatar szagoruyko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

functional-zoo's Issues

Extract features from pre-trained model

To extract features from an arbitrary layer with say, VGG19, given an input image "elephant.jpg", the code in keras+TF is simply:

from keras.applications.vgg19 import VGG19
from keras.preprocessing import image
from keras.applications.vgg19 import preprocess_input
from keras.models import Model
import numpy as np

base_model = VGG19(weights='imagenet')
model = Model(input=base_model.input, output=base_model.get_layer('block4_pool').output)

img_path = 'elephant.jpg'

img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

block4_pool_features = model.predict(x)

This can be turned into a function to support multiple calls. How is this achieved in PyTorch?

Preprocessing to use with pretrained weights

Hello, thanks for sharing your code!

I'd like to know what preprocessing you've used to produce the ImageNet weights. Can you confirm that you used meanstd normalization?

All the best,
Carl

need torch in order to run "Tensorflow model definition"

Hi,

In the "Tensorflow model definition" section, the parameters are taken from torch:
(params = {k: v.numpy() for k,v in torch.load('wide-resnet-50-2-export.pth').items()})

How can I run this without using torch?
Thanks!

Error reading a hdf5 file cpp_parser

HDF5-DIAG: Error detected in HDF5 (1.8.16) thread 139655733122880:
  #000: ../../../src/H5G.c line 467 in H5Gopen2(): unable to open group
    major: Symbol table
    minor: Can't open object
  #001: ../../../src/H5Gint.c line 320 in H5G__open_name(): group not found
    major: Symbol table
    minor: Object not found
  #002: ../../../src/H5Gloc.c line 430 in H5G_loc_find(): can't find object
    major: Symbol table
    minor: Object not found
  #003: ../../../src/H5Gtraverse.c line 861 in H5G_traverse(): internal path traversal failed
    major: Symbol table
    minor: Object not found
  #004: ../../../src/H5Gtraverse.c line 641 in H5G_traverse_real(): traversal operator failed
    major: Symbol table
    minor: Callback failed
  #005: ../../../src/H5Gloc.c line 385 in H5G_loc_find_cb(): object 'data_0' doesn't exist
    major: Symbol table
    minor: Object not found
terminate called after throwing an instance of 'H5::FileIException'
Aborted (core dumped)

I am trying to read the weights of yolo network ./hdf5_app /home/myst/yolo/yolo.h5

Visualizer: Conv2d seems to terminate graph traversing

The visualizer has been working properly, so good.
But after I updated pytorch, a model containing Conv2d is not property rendered:
The first Conv2d layer is shown as 'ConvNdBackward' and the graph is not traversed further.

If I remove all Conv2d, it works well again.
Thank you.

RuntimeError: Cannot open file. This file was likely created with Python 2 and an old hickle version.

File "/usr/local/lib/python3.6/dist-packages/hickle/hickle.py", line 526, in load
raise RuntimeError("Cannot open file. This file was likely"
RuntimeError: Cannot open file. This file was likely created with Python 2 and an old hickle version.

How can we debug in this situation above? It is problem of using python3 but unsupported from hickle.

hickle.py

 elif VER_MAJOR == 2:
                    if six.PY2:
                        warnings.warn("Hickle file appears to be old version (v2), attempting legacy loading...")
                        import hickle_legacy2
                        return hickle_legacy2.load(fileobj, safe=safe)
                    else:
                        raise RuntimeError("Cannot open file. This file was likely"
                                           " created with Python 2 and an old hickle version.")
                # There is an unfortunate period of time where hickle 2.1.0 claims VERSION = int(3)
                # For backward compatibility we really need to catch this.
                # Actual hickle v3 files are versioned as A.B.C (e.g. 3.1.0)

get AttributeError: grad_fn when use make_dot

when I use following code to visualize the torch pretrained resnet18 model, I get AttributeError: grad_fn, at line: add_nodes(var.grad_fn)

input=torch.randn(1,3,224,224)  
model=models.resnet18(pretrained=True)
for param in model.parameters():
     param.requires_grad = True
params = model.state_dict()
y=model(Variable(input))
print y
dot=make_dot(y, params)

tensorflow image input format and means

Hi @szagoruyko,

First of all thanks for converting the wide resnet model to tensorflow :)

I have some question about the details in WRN50 model:

  1. The Input image, is it RGB, BGR, or others? I saw the inputs.permute(0,2,3,1) and its kinda unintuitive.
  2. What about image mean?

Pretrained model

When trying to load the weights of the pretrained wide resnet for ImageNet, using Tensorflow, I get the error message:
"RuntimeError: Cannot open file. This file was likely created with Python 2 and an old hickle version."

I haven't found any solution to this. Can you help me find weights that can be used with python 3.6?
Thanks,
Jenny

Issue with output torch Variable in visualize.py throwing an attribute error (grad_fn)

Hey, so I am facing the same issue as issue #14 . Although what you said is correct about the model.state_dict(), the error about grad_fn arises from var, which is the output variable of the model and not the params dictionary. Any ideas on how to fix this?

As for the model.state_dict() part, I think it can be converted to the required (name, Variable) format using;

params = model.state_dict()
for k in sorted(params.keys()):
	v = params[k]
	params[k] = autograd.Variable(v, requires_grad=True)

I printed this out, and it seemed fine.

Need help to remove the var.grad_fn attribute error though.
Thanks.

Error in visualize code

I'm seeing this:

TypeError: Don't know how to create Python object for N5torch8autograd8VariableE

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 15, in add_nodes
  File "<stdin>", line 15, in add_nodes
  File "<stdin>", line 15, in add_nodes
  File "<stdin>", line 15, in add_nodes
  File "<stdin>", line 11, in add_nodes

For reference with line numbers, I have the function as:

>>> def add_nodes(var):
...         print(var)
...         print("didthatone")
...         if var not in seen:
...             if isinstance(var, Variable):
...                 value = '('+(', ').join(['%d'% v for v in var.size()])+')'
...                 dot.node(str(id(var)), str(value), fillcolor='lightblue')
...             else:
...                 dot.node(str(id(var)), str(type(var).__name__))
...             seen.add(var)
...             if hasattr(var, 'previous_functions'):
...                 for u in var.previous_functions:
...                     print(u)
...                     dot.edge(str(id(u[0])), str(id(var)))
...                     add_nodes(u[0])

Runtime error in make_dot

Hi,

thanks a lot for making that function available!
However, when I try calling
make_dot(loss)
I get the error below.

Any idea how that could be fixed?

Thanks again!

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-10-b7f0e150648d> in <module>()
      1 from visualize import make_dot
----> 2 make_dot(loss)

/home/carnd/basic_pytorch/visualize.py in make_dot(var, params)
     55                     dot.edge(str(id(t)), str(id(var)))
     56                     add_nodes(t)
---> 57     add_nodes(var.grad_fn)
     58     return dot

/home/carnd/basic_pytorch/visualize.py in add_nodes(var)
     50                     if u[0] is not None:
     51                         dot.edge(str(id(u[0])), str(id(var)))
---> 52                         add_nodes(u[0])
     53             if hasattr(var, 'saved_tensors'):
     54                 for t in var.saved_tensors:

/home/carnd/basic_pytorch/visualize.py in add_nodes(var)
     50                     if u[0] is not None:
     51                         dot.edge(str(id(u[0])), str(id(var)))
---> 52                         add_nodes(u[0])
     53             if hasattr(var, 'saved_tensors'):
     54                 for t in var.saved_tensors:

/home/carnd/basic_pytorch/visualize.py in add_nodes(var)
     50                     if u[0] is not None:
     51                         dot.edge(str(id(u[0])), str(id(var)))
---> 52                         add_nodes(u[0])
     53             if hasattr(var, 'saved_tensors'):
     54                 for t in var.saved_tensors:

/home/carnd/basic_pytorch/visualize.py in add_nodes(var)
     50                     if u[0] is not None:
     51                         dot.edge(str(id(u[0])), str(id(var)))
---> 52                         add_nodes(u[0])
     53             if hasattr(var, 'saved_tensors'):
     54                 for t in var.saved_tensors:

/home/carnd/basic_pytorch/visualize.py in add_nodes(var)
     50                     if u[0] is not None:
     51                         dot.edge(str(id(u[0])), str(id(var)))
---> 52                         add_nodes(u[0])
     53             if hasattr(var, 'saved_tensors'):
     54                 for t in var.saved_tensors:

/home/carnd/basic_pytorch/visualize.py in add_nodes(var)
     51                         dot.edge(str(id(u[0])), str(id(var)))
     52                         add_nodes(u[0])
---> 53             if hasattr(var, 'saved_tensors'):
     54                 for t in var.saved_tensors:
     55                     dot.edge(str(id(t)), str(id(var)))

RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.

Show how to use models for fine-tuning

The readme explains that all the models listed so far have bn params integrated into the conv weights, for performance, thus making these models not useful for fine-tuning. Fine-tuning is, perhaps, the most common thing that people use pre-trained models for, so it would be great it you could do one of the following:

  • Explain how to separate out the bn params in the existing models
  • Show how to re-create the models so that others can do so without the bn param integration
  • Make every model available in both integrated and standard format

Many thanks for this great project!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.