microsoft / tensorwatch

Debugging, monitoring and visualization for Python Machine Learning and Data Science
MIT License
3.42k stars 362 forks source link

pip package missing json file #9

Closed sakaia closed 5 years ago

sakaia commented 5 years ago

I try to execute following cnn_pred_explain notebook on Colab. https://github.com/microsoft/tensorwatch/blob/master/notebooks/cnn_pred_explain.ipynb

But I failed to execute it, because following error appeared.

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-5-b08090dd95a6> in <module>()
     10 image_utils.show_image(img)
     11 probabilities = imagenet_utils.predict(model=model, images=[img])
---> 12 imagenet_utils.probabilities2classes(probabilities, topk=5)
     13 input_tensor = imagenet_utils.image2batch(img)
     14 prediction_tensor = pytorch_utils.int2tensor(239)

2 frames
/usr/local/lib/python3.6/dist-packages/tensorwatch/imagenet_utils.py in __init__(self, json_path)
     54         json_path = json_path or os.path.join(os.path.dirname(__file__), 'imagenet_class_index.json')
     55 
---> 56         with open(os.path.abspath(json_path), "r") as read_file:
     57             class_json = json.load(read_file)
     58             self._idx2label = [class_json[str(k)][1] for k in range(len(class_json))]

FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.6/dist-packages/tensorwatch/imagenet_class_index.json'

In my guess, python pip package misses json file inclusion.

Reference A Simple Guide for Python Packaging https://medium.com/small-things-about-python/lets-talk-about-python-packaging-6d84b81f1bb5

sakaia commented 5 years ago

On Colab, I execute following script. image_data should be include on python package. Then following git clone command will be removed.

!pip install tensorwatch
!pip install lime
!git clone http://github.com/microsoft/tensorwatch
!cp -r tensorwatch/data ..
%matplotlib inline
from tensorwatch.saliency import saliency
from tensorwatch import image_utils, imagenet_utils, pytorch_utils
model = pytorch_utils.get_model('resnet50')
img = image_utils.open_image('../data/test_images/dogs.png', convert_mode='RGB')
image_utils.show_image(img)
probabilities = imagenet_utils.predict(model=model, images=[img])
imagenet_utils.probabilities2classes(probabilities, topk=5)
input_tensor = imagenet_utils.image2batch(img)
prediction_tensor = pytorch_utils.int2tensor(239)
results = saliency.get_image_saliency_results(model, img, input_tensor, prediction_tensor)
figure = saliency.get_image_saliency_plot(results)
sytelus commented 5 years ago

Thanks for reporting the issue. We have modified setup.py to include the missing file and address other issues. So if you do

pip install tensorwatch --upgrade

then you should be good to go!

I also created Colab Notebook but for some reason it is erroring out in last step. This is not reproducible in my local box with either PyTorch 1.0 or 1.1 so its strange...

sakaia commented 5 years ago

Thank you, It works fine for Colab. But I cannot comment on your local machine behavior.