moein-shariatnia / deep-learning Goto Github PK
View Code? Open in Web Editor NEWIn-depth tutorials on deep learning. The first one is about image colorization using GANs (Generative Adversarial Nets).
License: MIT License
In-depth tutorials on deep learning. The first one is about image colorization using GANs (Generative Adversarial Nets).
License: MIT License
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.
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?
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")
Hi,
i'm trying to run your code but in google colab the time needed for each epoch si about 4h:
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.
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?
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",
I made a version in PyTorch Lightning (based on your work) using a diferente Patch Discriminator. My results tend to be more "conservative" than yours. Your implementation outputs more colorful results. I would like to know if you can check my code to see were I can improve. Is that possible? My code is available on Kaggle (https://www.kaggle.com/code/luizclaudioandrade/b-w-colorizing-pytorch-lightning/notebook).
Thanks in advance!
sir, How to do prediction on single image?
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
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: `
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.