torch2coreml icon indicating copy to clipboard operation
torch2coreml copied to clipboard

Is it possible to load pytorch model (.pth)?

Open theheena opened this issue 8 years ago • 4 comments

Hi, I have a pytorch pre-trained model (.pth) for neural art style. Is it possible to convert this model into mlmodel?

theheena avatar Oct 31 '17 06:10 theheena

Hi @theheena , Although torch7 and pytorch seem similar, models are not compatible with each other. Only torch7 -> pytorch (legacy.nn) is suitable for conversion. But not vice versa. Thus it is not possible to convert .pth pre-trained pytorch model.

opedge avatar Oct 31 '17 12:10 opedge

Hi @opedge ,

Thank you for your answer.

theheena avatar Nov 02 '17 09:11 theheena

Hi @opedge ,

I have one more question regarding the training of new model. In the fast-neural-style folder, their is a file called DataLoader.lua which contains following lines,

self.image_paths = { train = '/train2014/images', val = '/val2014/images', }

Is that the train and val are paths to the training and validation images? This file also takes in input .h5 file which is already being created with the train and validation images.

I got following error, /fast_neural_style/DataLoader.lua:38: attempt to call method 'dataspaceSize' (a nil value)

I think this is due to the path specified in self.image_paths. Please let me know if it is the solution.

theheena avatar Nov 02 '17 11:11 theheena

Hi @theheena , I think DataLoader.lua is intended for training model. torch2coreml can convert only already trained model into CoreML for inference on mobile device. I don't know exactly about internal structure of DataLoader.lua.

opedge avatar Nov 02 '17 12:11 opedge