8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【python】絶対パスに~(チルダ)は使わない【tensorflow】

Posted at

はじめに

tensorflowにて,絶対パスでモデルを指定してrestoreしようとしたらエラーが出て詰まったので自分用メモ.
結論から書くと,ホームディレクトリを~(チルダ)で指そうとしていたのがマズかった.

環境

OS: Ubuntu 14.04.4 LTS
python: Ver 2.7.6
tensorflow: Ver 1.2.1

(解決)os.path.expanduserでホームディレクトリを取得

os.path.expanduser()でカレントユーザのホームディレクトリを取得できる.絶対パス指定の時はとりあえずこれを使えば間違いなさそう.

import os.path

print(os.path.expanduser('~'))  
# => /Users/ユーザー名

ちなみに自分はその場しのぎで相対パスで指定した.

参考URL

8
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?