caffe icon indicating copy to clipboard operation
caffe copied to clipboard

how to build a new app.py

Open wzq12138 opened this issue 11 years ago • 14 comments

I have just changed the code like this 'model_def_file': ( '{}/models/bvlc_reference_caffenet/imagenet_deploy.prototxt'.format(REPO_DIRNAME)), 'pretrained_model_file': ( '{}/models/bvlc_reference_caffenet/caffe_gaoxin_train_iter_3500'.format(REPO_DIRNAME)), 'mean_file': ( '{}/python/caffe/imagenet/ilsvrc_2012_mean.npy'.format(REPO_DIRNAME)), 'class_labels_file': ( '{}/data/ilsvrc12/test.txt'.format(REPO_DIRNAME)), 'bet_file': ( '{}/data/ilsvrc12/imagenet.bet.pickle'.format(REPO_DIRNAME)),

I think I should only change the model , class_labels_file,and pretrained_model_file ,but it comes some error,because I classisy only 9 things,not 1000.the error is like this INFO:root:Classification error: index 278 is out of bounds for size 9 .by the way ,,what does the imagenet.bet.pickle,should I change this file,and how?

wzq12138 avatar Mar 12 '15 07:03 wzq12138

Did you change the synset_words file?

waelHamdan avatar Mar 12 '15 07:03 waelHamdan

@waelHamdan I have changed the synset_words file,I changed it like that 1 red 2 blue ... 9 grenn

wzq12138 avatar Mar 12 '15 10:03 wzq12138

@waelHamdan do you know what is the imagenet.bet.pickle file,I think it is the cause the index.htm file

wzq12138 avatar Mar 12 '15 10:03 wzq12138

as they say: The bet_file that is loaded in the demo provides the graph structure and names of all relevant ImageNet nodes as well as measures of information gain between them. Please see the "Hedging your bets" paper from CVPR 2012 for further information.

waelHamdan avatar Mar 12 '15 10:03 waelHamdan

maybe it is good to comment the part of code that contain it,

waelHamdan avatar Mar 12 '15 10:03 waelHamdan

@Yangqing can you answer me the question

wzq12138 avatar Mar 12 '15 11:03 wzq12138

@waelHamdan you mean ,I should comment the code 'bet_file': ( '{}/data/ilsvrc12/imagenet.bet.pickle'.format(REPO_DIRNAME)),

I did not floow you,I think this file is important,and maybe there is the way to build a bet_file with my own model

wzq12138 avatar Mar 12 '15 11:03 wzq12138

@shelhamer

wzq12138 avatar Mar 17 '15 02:03 wzq12138

@waelHamdan I have comment all the "bet",and the another is that Did you provide a valid URL or a valid image file

in the index.html, {% if has_result %} {% if not result[0] %}

{{ result[1] }} Did you provide a valid URL or a valid image file?
{% else %}

I think,it should change some code in the app.py about "result",but I do not know how

wzq12138 avatar Mar 17 '15 08:03 wzq12138

@wzq12138

This is the code, mainly: you comment the lines that compute bet, and in the last two lines you replace bet_result with meta.. I tried it, and it is working, but just giving the same result for the two taps and that is normal # Compute expected information gain #expected_infogain = np.dot( # self.bet['probmat'], scores[self.bet['idmapping']]) #expected_infogain *= self.bet['infogain']

        # sort the scores
        #infogain_sort = expected_infogain.argsort()[::-1]
        #bet_result = [(self.bet['words'][v], '%.5f' % expected_infogain[v])
        #              for v in infogain_sort[:3]]
        logging.info('bet result: %s', str(meta))

        return (True, meta, meta, '%.3f' % (endtime - starttime))

waelHamdan avatar Mar 17 '15 08:03 waelHamdan

@waelHamdan I tried it ,and it is successed,but there is still two problem,first ,the "up-load" button is failed,onece I up an image from my disk,there is the error like that: ERROR:main:Exception on /classify_upload [POST] Traceback (most recent call last): File "/home/wzq/anaconda/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/home/wzq/anaconda/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/wzq/anaconda/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/wzq/anaconda/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/home/wzq/anaconda/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functionsrule.endpoint File "examples/web_demo/app.py", line 78, in classify_upload imagesrc=embed_image_html(image) File "examples/web_demo/app.py", line 87, in embed_image_html image_pil.save(string_buf, format='png') File "/home/wzq/anaconda/lib/python2.7/site-packages/PIL/Image.py", line 1673, in save save_handler = SAVE[format.upper()] # unknown format KeyError: 'PNG'

second,if I copy an image from my disk,then paste it like /home/wzq/image/car.jpg on the url input box,it is successed,but the image would not appear ,it will not show up,but in the Maximally accurate shows right. I think it is error on the index.html

wzq12138 avatar Mar 18 '15 02:03 wzq12138

please ask usage questions on caffe-users -- this issues tracker is primarily for Caffe development discussion. Thanks!

pathak22 avatar Mar 30 '15 18:03 pathak22

How do you solve the problem? Do you follow this method?

Compute expected information gain

#expected_infogain = np.dot(

self.bet['probmat'], scores[self.bet['idmapping']])

#expected_infogain *= self.bet['infogain']

sort the scores

#infogain_sort = expected_infogain.argsort()[::-1] #bet_result = [(self.bet['words'][v], '%.5f' % expected_infogain[v])

for v in infogain_sort[:3]]

logging.info('bet result: %s', str(meta))

return (True, meta, meta, '%.3f' % (endtime - starttime))

zhaozhijun1988 avatar Jun 30 '15 06:06 zhaozhijun1988

it works @waelHamdan

zhangwenwen avatar Feb 28 '17 05:02 zhangwenwen