I have a simulation inside Blender that I would like to control externally using the TensorFlow library. The complete process would go something like this:
while True:
state = observation_from_blender()
action = find_action_using_tensorflow_neural_net(state)
take_action_inside_blender(action)
I don't have much experience with the threading or subprocess modules and so am unsure as to how I should go about actually building something like this.
Rather than mess around with Tensorflow connections and APIs, I'd suggest you take a look at the Open AI Universe Starter Agent[1]. The advantage here is that as long as you have a VNC session open, you can connect a TF based system to do reinforcement learning on your actions.
Once you have a model constructed via this, you can focus on actually building a lower level API system for the two things to talk to each other.
[1] https://github.com/openai/universe-starter-agent
Thanks for your response. Unfortunately, trying to get Universe working with my current setup was a bit of a pain. I'm also on a fairly tight deadline so I just needed something that worked straight away.
I did find a somewhat DIY solution that worked well for my situation using the pickle module. I don't really know how to convert this approach into proper pseudocode, so here is the general outline:
Process 1 - TensorFlow:
load up TF graph
wait until pickled state arrives
while not terminated:
Process 2 - Blender:
run simulation until next action required
pickle state
wait until pickled action arrives
Process 1 - TensorFlow:
unpickle state
feedforward state through neural net, find action
pickle action
wait until next pickled state arrives
Process 2 - Blender:
unpickle action
take action
This approach worked well for me, but I imagine there are more elegant low level solutions. I'd be curious to hear of any other possible approaches that achieve the same goal.
I did this to install tensorflow with the python version that comes bundled with blender.
Blender version: 2.78
Python version: 3.5.2
First of all you need to install pip for blender's python. For that I followed instructions mentioned in this link: https://blender.stackexchange.com/questions/56011/how-to-use-pip-with-blenders-bundled-python. (What I did was drag the python3.5m icon into the terminal and then further type the command '~/get-pip.py').
Once you have pip installed you are all set up to install 3rd party modules and use them with blender.
Navigate to the bin folder insider '/home/path to blender/2.78/' directory. To install tensorflow, drag the python3.5m icon into terminal, then drag pip3 icon into terminal and give the command install tensorflow.
I got an error mentioning module lib2to3 not found. Even installing the module didn't help as I got the message that no such module exists. Fortunately, I have python 3.5.2 installed on my machine. So navigate to /usr/lib/python3.5 and copy the lib2to3 folder from there to /home/user/blender/2.78/python/lib/python3.5 and then again run the installation command for tensorflow. The installation should complete without any errors. Make sure that you test the installation by importing tensorflow.
Related
I recently got a really awesome gaming laptop that I use for all my heavy-duty computer tasks. There's one problem. The RGB lighting isn't changing from its default blue color. I want to change the color so I thought I could do that using an SDK provided by ASUS to change it with python; since the aura software is garbage.
import win32com.client
auraSdk = win32com.client.Dispatch("aura.sdk.1")
auraSdk.SwitchMode()
devices = auraSdk.Enumerate(0)
for dev in devices:
for i in range(dev.Lights.Count):
dev.Lights(i).color = 0x0000FF00
This code, which I copied off of https://www.asus.com/microsite/aurareadydevportal/tutorial_python.html, didn't work at first because I didn't have the right module installed. So I did a simple git clone and a pip install and it ran. Then I got this other error.
can't load MsIo.dll(SMB)!
can't load MsIo.dll(SMB)!
Check DRAM Module. (0)
I don't really understand what MsIo.dll is for or why there is SMB(Server Message Block) within parentheses.
and it doesn't give much information on what to check in my DRAM Module.
Help please?
At first, I tried to download the necessary modules and clone the necessary packages. I was expecting that it works. It ran this time, but I got the error. "can't load MsIo.dll(SMB)", twice then "Check DRAM Module". I don't really understand what MsIo.dll does or what I am supposed to do to resolve this issue.
I have a 2021 Macbook pro M1.
It is a well recognized problem that it conflicts with Tensoflow library, see here or here; in particular this last one was exactly the issue I experienced: when I tried to import tensorflow in jupyter notebook via the command
import tensorflow as tf
then the message
The kernel appears to have died. It will restart automatically.
appeared. Then searching in the above linked discussions, I have the feeling that the suggestion given at some point, which points at this link, SEEMS to be useful.
FIRST QUESTION: is this a/the solution for the M1-Tensorflow conflict?
I say "it seems" since before trying that I have been into the kind of tornado of desperate attempts leading a beginner like me to search for hints all around the web and then copy-paste commands taken here and there into the Terminal without understanding them all properly.
On one hand it sounds dumb, I admit, on the other the cost of understanding everything goes well beyond my humble intentions of learning some ML.
So, the final result is that I have a complete mess in my computer; the old libraries like numpy don't work anymore (when I import them inside a Python3 page opened with jupyter notebook with the command import numpy as np, the message
ModuleNotFoundError: No module named 'numpy'
appears), then the pip command doesn't work, if I use the pip3 to install, nothing changes. I read somewhere to use a virtual enviroment, and I followed the instructions even if I wasn't really aware of what I was doing; I downloaded XCode, miniforge3...
Well, I guess that there is somebody out there who can relate with this.
SECOND PROBLEM: I would like to clean-up everything dealing with Python/pip/anaconda and so on and install everything from scratch, possibly following the above link to solve the M1-tensorflow conflict...if it is correct. How can I do that?
Can somebody help me, please? Thanks
I am a scientific researcher using a home-written software called Python Microscopy developed by David Baddeley at Yale University (documentation available here http://python-microscopy.org/). I am running the program out of a Python 2.7 conda environment (called snakes), on which David Baddeley has his own channel. To perform parts of the image analysis, the program requires the use of launchworkers.py, which is described here http://python-microscopy.org/doc/LocalisationAnalysis.html. When I try to run launchworkers out of the terminal, I got the following:
(snakes) Sabinas-MBP:~ sabinahaque$ launchWorkers
killing ['/anaconda/envs/snakes/bin/python','/anaconda/envs/snakes/lib/python2.
7/site-packages/PYME/ParallelTasks/taskServerZC.py']
killing ['/anaconda/envs/snakes/bin/python','/anaconda/envs/snakes/lib/python2.
7/site-packages/PYME/ParallelTasks/taskWorkerZC.py']
killing ['/anaconda/envs/snakes/bin/python','/anaconda/envs/snakes/lib/python2.
7/site-packages/PYME/ParallelTasks/taskWorkerZC.py']
killing ['/anaconda/envs/snakes/bin/python','/anaconda/envs/snakes/lib/python2.
7/site-packages/PYME/ParallelTasks/taskWorkerZC.py']
killing ['/anaconda/envs/snakes/bin/python','/anaconda/envs/snakes/lib/python2.
7/site-packages/PYME/ParallelTasks/taskWorkerZC.py']
Starting PYME taskServer ...
(snakes) Sabinas-MBP:~ sabinahaque$ /anaconda/envs/snakes/lib/python2.7/site-
packages/PYME/ParallelTasks/fitMonP.py:221: wxPyDeprecationWarning: Using
deprecated class PySimpleApp.
app = wx.PySimpleApp(0)
This program needs access to the screen.
Please run with a Framework build of python, and only when you are
logged in on the main display of your Mac.
I have done some searching and get the general consensus that changing the path that the environment is running out of will perhaps fix my problem, but I am unsure of how to do this. Does anyone have an idea of how I should go about fixing this? I'm pretty new to Python and StackOverflow so please try to walk me through as much detail as possible!
I'm a freshman, and have just started my trip toward machine learning. I followed a book and the video tutorial of Josh Gordon (https://www.youtube.com/watch?v=cSKfRcEDGUs), but was stopped at "TensorFlow for poets", in which says:
# In Docker
python tensorflow/examples/image_retraining/retrain.py \
--bottleneck_dir=/tf_files/bottlenecks \
--how_many_training_steps 500 \
--model_dir=/tf_files/inception \
--output_graph=/tf_files/retrained_graph.pb \
--output_labels=/tf_files/retrained_labels.txt \
--image_dir /tf_files/flower_photos
And I got 2 problems here:
there's no such directory called 'image_retraining' nor file called retrain.py;
the docker can't be opened.
The first problem seems easy to solve as I found the Tensorflow Retrain on Windows,
but the second one remain unsolved. Every time I start the "Boot2DockerStart", it will flash an error saying 'error in run: Failed to start machine "boot2docker-vm": exit status 1' and then quit. So I searched, most answers are saying that the Virtualization is disabled, but I checked that though the Task Manager, On which the Virtualization Status is 'Enable', which really confused me...
So I wonder: How to fix the docker problem? Is there a way that can run the Retrain without docker? And, if both the problems are difficult to solve, am I supposed to install a linux?
P.S. I'm using Win10, python version is 3.5 which is installed using Anaconda and coding in VS2015, tensorflow version is gpu-0.12.1
You can see a more complete set of instructions in "TensorFlow For Poets - Setting up" (for Linux and Mac)
On Windows, make sure your Docker Toolbox (the one using Boot2docker) is properly setup.
Make sure, on Windows 10, that you don't have the Hyper-V Windows already activated, as both Hyper-V and VirtualBox have some issues running together.
pexpect has gone through big changes since the version provided by Ubuntu 15.04 (3.2). When installing newest version of pexpect using pip3, this minimal program that previously successfully gave terminal emulation over serial console does not work any more:
#!/usr/bin/python3
import serial
import pexpect.fdpexpect
ser = serial.Serial("/dev/ttyS0", baudrate=115200)
spawn = pexpect.fdpexpect.fdspawn(ser)
spawn.interact()
The newer API is missing interact() method in class pexpect.fdpexpect.fdspawn which used to be there.
Question: how is the newer version of pexpect (currently 4.2.1) supposed to be used to provide free manual interaction with file object (serial port in this case)?
Alternatively, question/work-around: I recognize I am using a bit heavy machinery for such a simple use case, any suggestions for other python libraries that can do the same as earlier version of pexpect could?
Code reading: Examples use pexpect.spawn(command_str) to get a spawn object which has interact() method; actually this pexpect.spawn() is the same as directly creating a pexpect.pty_spawn.spawn object which has this method. On the other hand, pexpect.fdpexpect.fdspawn() will construct a pexpect.fdpexpect.fdspawn class which is missing interact() method. Both of these spawn classes derive from pexpect.spawnbase.SpawnBase class. Based on my quick reading, this looks like regression that resulted from refactoring on the way to version 4.x.
Browsing the pexpect issues, found #351, #356, and the newly submitted #377. By my quick reading, it seems this is a regression that was brought by uncompleted refactoring along the way towards new major release version 4. There are three possible avenues:
Make sure to install older version:
$ pip3 install "pexpect<3"
(or make sure that the version installed by other system is 3.x).
Fix pexpect by yourself.
Use some other python library.
These avenues were all more or less hinted by github user #takluyver, apparently maintainer of pexpect in comment to issue #351:
#jquast any thoughts on what to do for this (and #356)? I feel bad that we've broken things people were doing with fdspawn, but I really don't want to make it inherit from the pty spawn class, and now that it works on Windows, I think it's important to preserve that too.
Maybe we should just say:
If you have legacy code that broke with Pexpect 4, downgrade to Pexpect 3.x (pip install pexpect<4)
If you're writing new code, use streamexpect instead of pexpect.