Giter Site home page Giter Site logo

moein-shariatnia / deep-learning Goto Github PK

View Code? Open in Web Editor NEW
148.0 3.0 52.0 22.73 MB

In-depth tutorials on deep learning. The first one is about image colorization using GANs (Generative Adversarial Nets).

License: MIT License

Jupyter Notebook 91.06% Python 8.94%
deeplearning machinelearning machine-learning deep-learning generative-adversarial-network image-colorization tutorial paper-implementations conditional-gan gan

deep-learning's Introduction

Deep Learning Tutorials and Projects

I will upload my deep learning tutorials and projects here.

The following table gives you information on the available tutorials and projects:

Name Description
1. Image Colorization Tutorial Using conditional GANs to colorize black and white images
2. HuggingFace Sequence Classification Tutorial Using DistilBERT with custom PyTorch dataset and model to classify tweets (data from Kaggle competition)
3. OpenAI CLIP A tutorial on simple implementation of OpenAI CLIP model

deep-learning's People

Contributors

moein-shariatnia 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

deep-learning's Issues

Code for using the trained model...

How to start the prediction process?

this code not working...

model = MainModel()
model.load_state_dict(torch.load("../input/colorizedmodel/final_model_weights.pt", map_location=device))
model.eval()
prediction = model("../input/global-wheat-detection/test/2fd875eaa.jpg")

AttributeError: 'function' object has no attribute 'named_parameters'

I tried to pip install fastai==2.4 but couldn't as colab couldn't find 2.4 version of fastai. so i just installed pip install fastai. whenever i try to run the trained model, i get the error

AttributeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 net_G = build_res_unet(n_input=1, n_output=2, size=256)
2 net_G.load_state_dict(torch.load("res18-unet.pt", map_location=device))
3 model = MainModel(net_G=net_G)
4 train_model(model, train_dl, 20)

3 frames
/usr/local/lib/python3.10/dist-packages/fastai/vision/learner.py in _get_first_layer(m)
32 "Access first layer of a model"
33 c,p,n = m,None,None # child, parent, name
---> 34 for n in next(m.named_parameters())[0].split('.')[:-1]:
35 p,c=c,getattr(c,n)
36 return c,p,n

AttributeError: 'function' object has no attribute 'named_parameters'

please let me know how to fix it. Thanks.

Error on pretrain_generator

Hello, excellent your model and it is well explained. Only while running the code did I encounter this error. Do you know how to solve it. Thank you

`/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py:481: UserWarning: This DataLoader will create 4 worker processes in total. Our suggested max number of worker in current system is 2, which is smaller than what this DataLoader is going to create. Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary.
cpuset_checked))

KeyboardInterrupt Traceback (most recent call last)
in ()
18 opt = optim.Adam(net_G.parameters(), lr=1e-4)
19 criterion = nn.L1Loss()
---> 20 pretrain_generator(net_G, train_dl, opt, criterion, 20)
21 torch.save(net_G.state_dict(), "res18-unet.pt")

6 frames
/usr/local/lib/python3.7/dist-packages/torch/autograd/init.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs)
154 Variable.execution_engine.run_backward(
155 tensors, grad_tensors
, retain_graph, create_graph, inputs,
--> 156 allow_unreachable=True, accumulate_grad=True) # allow_unreachable flag
157
158

KeyboardInterrupt: `

Issue with running infer file

Hi Moein,
It looks like there is some difference in keys in the saved model and model architecture. While using the infer file, I am getting the following error. Any thoughts on how to fix this?

model initialized with norm initialization
model initialized with norm initialization
RuntimeError Traceback (most recent call last)
in <cell line: 11>()
9 saved_model_dict = torch.load('final_model_weights.pt', map_location=device)
10 model = MainModel()
---> 11 model.load_state_dict(saved_model_dict)
12
13 # Load the black and white image and resize it

/usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)
2039
2040 if len(error_msgs) > 0:
-> 2041 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
2042 self.class.name, "\n\t".join(error_msgs)))
2043 return _IncompatibleKeys(missing_keys, unexpected_keys)

RuntimeError: Error(s) in loading state_dict for MainModel:
Missing key(s) in state_dict: "net_G.model.model.0.weight",

How to test the code on custom data?

I went through your codebase and it is excellently explaining the whole process, but I could not find how to test the model for custom images after training.

I was thinking to extend this project and use this model for a webapp. Therefore, I need to know how to test it for custom images?

The code takes 4h foe each epoch in google colab.

Hi,
i'm trying to run your code but in google colab the time needed for each epoch si about 4h:
image

I also downloaded the notebook and run it on my local machine with cuda and GTX 1050 and the time needed is about 30min for every epoch.

Do you have an idea why this happens? It seems should be necessary only 3-4min for every epoch.

EDIT:
I forgot to change the runtime type to colab, now it takes about 10min, however i cant't understand why on my lapton takes 30-40min.

can't create the body of ResNet18

Hi! first of all i have to say thank you for this code, it's a great job!

I was trying this part of the code:

from fastai.vision.data import create_body
from fastai.vision import models
from torchvision.models.resnet import resnet18
from fastai.vision.models.unet import DynamicUnet

def build_res_unet(n_input=1, n_output=2, size=256):
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    body = create_body(resnet18, n_in = n_input, pretrained=True, cut=-2)
    net_G = DynamicUnet(body, n_output, (size, size)).to(device)
    return net_G

net_G = build_res_unet(n_input=1, n_output=2, size=256) 

but I keep getting an error:

TypeError: create_body() got an unexpected keyword argument 'n_in'
but in the fastai docs the n_in parameter is present.
How do you think we can resolve?

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.