Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B4016200C73 for ; Wed, 10 May 2017 22:16:11 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B29A1160B9C; Wed, 10 May 2017 20:16:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D3F1E160B99 for ; Wed, 10 May 2017 22:16:10 +0200 (CEST) Received: (qmail 93622 invoked by uid 500); 10 May 2017 20:16:09 -0000 Mailing-List: contact issues-help@systemml.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@systemml.incubator.apache.org Delivered-To: mailing list issues@systemml.incubator.apache.org Received: (qmail 93610 invoked by uid 99); 10 May 2017 20:16:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 May 2017 20:16:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 7F6851A02E9 for ; Wed, 10 May 2017 20:16:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.201 X-Spam-Level: X-Spam-Status: No, score=-99.201 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 43cXuVFBpFgw for ; Wed, 10 May 2017 20:16:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id D319D5FD6D for ; Wed, 10 May 2017 20:16:05 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 22994E0D4D for ; Wed, 10 May 2017 20:16:05 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 394A121E11 for ; Wed, 10 May 2017 20:16:04 +0000 (UTC) Date: Wed, 10 May 2017 20:16:04 +0000 (UTC) From: "Mike Dusenberry (JIRA)" To: issues@systemml.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (SYSTEMML-1583) Implement converter in Python to convert caffemodel in SystemML format MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 10 May 2017 20:16:11 -0000 [ https://issues.apache.org/jira/browse/SYSTEMML-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16005332#comment-16005332 ] Mike Dusenberry commented on SYSTEMML-1583: ------------------------------------------- Definitely think it is a great idea to be able to accept Caffe model files, in addition to the protobuf definitition files. In the near future, we can also extend this to Keras, using the same infrastructure from the base of Caffe2DML. I agree with Fred that it would be ideal to use Caffe files directly so that users can seamlessly move from Caffe(2) to SystemML. It would be nice to be able to simply pass in URLs of protobufs & model files, and the system could cache them locally to avoid having to download them repeatedly. We could possibly even cache the SystemML binary format of the models transparently for the user. Overall, we need to continue to focus on flexibility for creating and running models at scale. > Implement converter in Python to convert caffemodel in SystemML format > ---------------------------------------------------------------------- > > Key: SYSTEMML-1583 > URL: https://issues.apache.org/jira/browse/SYSTEMML-1583 > Project: SystemML > Issue Type: Sub-task > Reporter: Niketan Pansare > Assignee: Arvind Surve > > Ideally, this converter shouldnot require the caffe to be installed. Please see http://stackoverflow.com/questions/37572948/extracting-weights-from-caffemodel-without-caffe-installed-in-python > An example code to convert a caffe model to csv if caffe is installed: > {code} > import caffe > import numpy as np > #net = caffe.Net('/home/biuser/nike/barista/VGG_ILSVRC_19_layers_train_val.prototxt', caffe.TEST) > net = caffe.Net('/home/biuser/VGG_trained_models/VGG_ILSVRC_19_layers_deploy.prototxt', '/home/biuser/VGG_trained_models/VGG_ILSVRC_19_layers.caffemodel', caffe.TEST) > #surgery.transplant(net, base_net) > for l in [ "conv1_1", "conv1_2", "conv2_1", "conv2_2", "conv3_1", "conv3_2", "conv3_3", "conv3_4", "conv4_1", "conv4_2", "conv4_3", "conv4_4", "conv5_1", "conv5_2", "conv5_3", "conv5_4", "fc6", "fc7", "fc8" ]: > w = net.params[l][0].data > w = w.reshape(w.shape[0], -1) > b = net.params[l][1].data > b = b.reshape(b.shape[0], -1) > # You may have to reshape it for fc layers > np.savetxt("VGG_trained_models/" + l + "_weight.csv", w, delimiter=",") > np.savetxt("VGG_trained_models/" + l + "_bias.csv", b, delimiter=",") > {code} > Here is an example pyspark script to test this JIRA: > {code} > from systemml.mllearn import Caffe2DML > from pyspark.sql import SQLContext > import numpy as np > import urllib, os, scipy.ndimage > from PIL import Image > import systemml as sml > # ImageNet specific parameters > img_shape = (3, 224, 224) > # Downloads a jpg image, resizes it to 224 and return as numpy array in N X CHW format > url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/MountainLion.jpg/312px-MountainLion.jpg' > outFile = 'test.jpg' > urllib.urlretrieve(url, outFile) > input_image = sml.convertImageToNumPyArr(Image.open(outFile), img_shape=img_shape) > # Download the ResNet network > import urllib > urllib.urlretrieve('https://raw.githubusercontent.com/niketanpansare/model_zoo/master/caffe/vision/resnet/ilsvrc12/ResNet_50_network.proto', 'ResNet_50_network.proto') > urllib.urlretrieve('https://raw.githubusercontent.com/niketanpansare/model_zoo/master/caffe/vision/resnet/ilsvrc12/ResNet_50_solver.proto', 'ResNet_50_solver.proto') > home_dir = os.path.expanduser('~') > # let's assume that this function is implemented as saveAsBinaryBlock(inputCaffeModel, outputDir) > resnet_pretrained_weight_dir = os.path.join(home_dir, 'model_zoo', 'caffe', 'vision', 'resnet', 'ilsvrc12', 'ResNet_50_pretrained_weights') > urllib.urlretrieve('https://deepdetect.com/models/resnet/ResNet-50-model.caffemodel', 'ResNet-50-model.caffemodel') > ####################################################################### > # To be implemented as part of this JIRA > sml.saveAsBinaryBlock('ResNet-50-model.caffemodel', resnet_pretrained_weight_dir) > ####################################################################### > resnet = Caffe2DML(sqlCtx, solver='ResNet_50_solver.proto', weights=resnet_pretrained_weight_dir, input_shape=img_shape) > resnet.predict(input_image) > # This should return array(['cougar, puma, catamount, mountain lion, painter, panther, Felis '], dtype='|S64') > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346)