From 3202498b5c195f103a7cd13609785c2bb97c2da6 Mon Sep 17 00:00:00 2001 From: adamhrv Date: Thu, 10 Jan 2019 12:09:12 +0100 Subject: gender nb --- .../notebooks/face_analysis/age_gender.ipynb | 187 +++++++++++++++++++++ 1 file changed, 187 insertions(+) (limited to 'megapixels/notebooks/face_analysis') diff --git a/megapixels/notebooks/face_analysis/age_gender.ipynb b/megapixels/notebooks/face_analysis/age_gender.ipynb index 98a18fc6..4f5b5cc7 100644 --- a/megapixels/notebooks/face_analysis/age_gender.ipynb +++ b/megapixels/notebooks/face_analysis/age_gender.ipynb @@ -246,6 +246,193 @@ "print(age)" ] }, + { + "cell_type": "code", + "execution_count": 319, + "metadata": {}, + "outputs": [], + "source": [ + "import pywavefront" + ] + }, + { + "cell_type": "code", + "execution_count": 320, + "metadata": {}, + "outputs": [], + "source": [ + "import pywavefront\n", + "\n", + "fp_obj = '/home/adam/Downloads/faces/Hillary_Clinton_official_Secretary_of_State_portrait_crop_0.obj'\n", + "scene = pywavefront.Wavefront(fp_obj, strict=True, encoding=\"iso-8859-1\", parse=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 336, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None []\n" + ] + } + ], + "source": [ + "for k, v in scene.meshes.items():\n", + " print(k, v.materials)\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": 332, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "C3F_V3F\n", + "133.0\n" + ] + }, + { + "ename": "TypeError", + "evalue": "'NoneType' object is not subscriptable", + "output_type": "error", + "traceback": [ + "\u001b[0;31m------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# Contains the vertex list of floats in the format described above\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmaterial\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvertices\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmaterial\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtexture\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;31m# Material properties\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: 'NoneType' object is not subscriptable" + ] + } + ], + "source": [ + "# Iterate vertex data collected in each material\n", + "for name, material in scene.materials.items():\n", + " # Contains the vertex format (string) such as \"T2F_N3F_V3F\"\n", + " # T2F, C3F, N3F and V3F may appear in this string\n", + " print(material.vertex_format)\n", + " # Contains the vertex list of floats in the format described above\n", + " print(material.vertices[0])\n", + " print(material.texture[0:10])\n", + " break\n", + " # Material properties\n", + " material.diffuse\n", + " material.ambient\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 356, + "metadata": {}, + "outputs": [], + "source": [ + "a = np.array([[1,100,10], [2,2,12], [3,3,13]])" + ] + }, + { + "cell_type": "code", + "execution_count": 358, + "metadata": {}, + "outputs": [], + "source": [ + "b = np.array([np.min(a[:, 0]), np.min(a[:, 1]), np.min(a[:, 2])]) " + ] + }, + { + "cell_type": "code", + "execution_count": 373, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(5, 3)\n", + "['b' 'g' 'r']\n", + "(5, 3)\n", + "['r' 'g' 'b']\n" + ] + } + ], + "source": [ + "colors = np.array([['b','g','r'], ['b','g','r'], ['b','g','r'], ['b','g','r'], ['b','g','r']])\n", + "print(colors.shape)\n", + "print(colors[0])\n", + "colors = np.array([c[::-1] for c in colors])\n", + "print(colors.shape)\n", + "print(colors[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 348, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 1., 100., 1.],\n", + " [ 2., 2., 2.],\n", + " [ 3., 3., 3.]])" + ] + }, + "execution_count": 348, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 374, + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path" + ] + }, + { + "cell_type": "code", + "execution_count": 375, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "PosixPath('/media/adam/ah8tb/work/megapixels_dev/megapixels/notebooks/face_analysis')" + ] + }, + "execution_count": 375, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "\n", + "Path.cwd()" + ] + }, + { + "cell_type": "code", + "execution_count": 377, + "metadata": {}, + "outputs": [], + "source": [ + "a = '/path/to/file.mp3'\n", + "fpp_a = Path(a)" + ] + }, { "cell_type": "code", "execution_count": null, -- cgit v1.2.3-70-g09d2