How can jupyter access a new tensorflow module ins

2019-08-05 02:19发布

问题:

Where should I stick the model folder? I'm confused because python imports modules from somewhere in anaconda (e.g. import numpy), but I can also import data (e.g. file.csv) from the folder in which my jupyter notebook is saved in.

The TF-Slim image models library is not part of the core TF library. So I checked out the tensorflow/models repository as:

 cd $HOME/workspace
 git clone https://github.com/tensorflow/models/

I'm not sure what $HOME/workspace is. I'm running a ipython/jupyter notebook from users/me/workspace/ so I saved it to:

users/me/workspace/models

In jupyter, I'll write:

import tensorflow as tf
from datasets import dataset_utils
# Main slim library
slim = tf.contrib.slim

But I get an error:

ImportError: No module named datasets

Any tips? I understand that my tensorflow code is stored in '/Users/me/anaconda/lib/python2.7/site-packages/tensorflow/init.pyc' so maybe I should save the new models folder (which contains models/datasets) there?

回答1:

From the error "ImportError: No module named datasets"
It seems that no package named datasets is present. You need to install datasets package and then run your script.
Once you install it, then you can find the package present in location
"/Users/me/anaconda/lib/python2.7/site-packages/" or at the
location "/Users/me/anaconda/lib/python2.7/"

Download the package from https://pypi.python.org/pypi/dataset and install it.
This should work



回答2:

You can find the folder address on your device and append it to system path.

import sys
sys.path.append(r"D:\Python35\models\slim\datasets")
import dataset_utils

You'll need to do the same with 'nets' and 'preprocessing'

sys.path.append(r"D:\Python35\models\slim\nets")
import vgg
sys.path.append(r"D:\Python35\models\slim\preprocessing")
import vgg_preprocessing