-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/darknet #356
base: master
Are you sure you want to change the base?
Feature/darknet #356
Conversation
junjihashimoto
commented
Apr 17, 2020
•
edited
edited
- Parser for darknet init file
- [] Read darknet weight file
- [] Implement yolov3
c221f32
to
b232244
Compare
fb5116b
to
30687b6
Compare
hasktorch/src/Torch/NN.hs
Outdated
@@ -48,11 +51,36 @@ instance Parameterized Parameter where | |||
flattenParameters = pure | |||
replaceOwnParameters _ = nextParameter | |||
|
|||
instance Parameterized a => Parameterized [a] where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this instance maybe you can also use this generalized version (sorry I hadn't gotten around to fixing the other one there yet, but this one seems good).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion.
I've changed the instance with generalized one.
Untyped instance can be fixed with 'OVERLAPS' pragma.
But typed instance can not be fixed with 'OVERLAPS' pragma.(I don't know why.)
hasktorch/src/Torch/NN.hs
Outdated
instance Parameterized Double where | ||
flattenParameters _ = [] | ||
replaceOwnParameters = return | ||
|
||
instance Parameterized [Int] where | ||
instance Parameterized Float where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this one I tried instance (Scalar a) => Parameterized a
, but GHC felt that was not okay. 😕
@@ -153,7 +178,7 @@ data Conv2d = | |||
Conv2d { | |||
conv2dWeight :: Parameter, | |||
conv2dBias :: Parameter | |||
} deriving (Show, Generic) | |||
} deriving (Show, Generic, Parameterized) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do that now? that's great! :)
let [a,b] = asValue v | ||
in (a,b) | ||
_dtype = error "Not implemented for tuple-type" | ||
_dims v = error "Not implemented for tuple-type" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[2]
?
let pad = (layerSize - 1) `div` 2 | ||
activation = if isLeaky then flip I.leaky_relu 0.1 else id | ||
in activation | ||
$ batchNormForward batchNorm train 0.90000000000000002 1.0000000000000001e-05 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic numbers 😾
30687b6
to
8096c74
Compare
@tycho01 Thank you for your reviewing. |
Int -> | ||
-- | [1, 1, grid, grid] | ||
Tensor | ||
gridY g = D.contiguous $ D.view [1, 1, g, g] $ I.t $ D.repeat [g, 1] $ arange' (0 :: Int) g (1 :: Int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/questions/49643225/whats-the-difference-between-reshape-and-view-in-pytorch
D.contiguous $ D.view is the same as D.reshape
0b2cec2
to
8aa9b4c
Compare
8aa9b4c
to
17b0f07
Compare
72f4438
to
80c90c9
Compare
loadWeights :: Darknet -> String -> IO Darknet | ||
loadWeights (Darknet layers) weights_file = do | ||
System.IO.withFile weights_file System.IO.ReadMode $ \handle -> do | ||
_ <- BS.hGet handle (5 * 4) -- skip header | ||
layers' <- forM layers $ \(i,layer) -> do | ||
let cur_params = flattenParameters layer | ||
new_params <- forM cur_params $ \param -> loadFloats handle (toDependent param) >>= makeIndependent | ||
return $ (i,replaceParameters layer new_params) | ||
return $ Darknet layers' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conv2d/BatchNorm's paramaters are loaded incorrectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why? I would like to try to do some work on loading pytorch models in the near future as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data is stored in the weight file as follows.
1, Bias of batchnorm
2, Weight of batchnorm
3, RunningMean of batchnorm
4, RunningVar of batchnorm
5, Weight of Conv2d
Conv2d has no bias.
https://github.com/eriklindernoren/PyTorch-YOLOv3/blob/master/models.py#L282-L317
The list of flattenParameters includes the bias of Conv2d with batchnorm.
Conv2d without batchnorm has bias.
Loader customization is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be easier to fix the ADT.