from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession
config = ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.8
session = InteractiveSession(config=config)
2020년 10월 20일 화요일
To set gpu memory rate manually when using keras
tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
add this code below on the top of the source code
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
# Currently, memory growth needs to be the same across GPUs
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
# Memory growth must be set before GPUs have been initialized
print(e)
2020년 10월 16일 금요일
After removing storyboard, app appears black in iOS with Objective-c.
1. set iOS version over 13 and make "Main Interface" is empty
2. add a ViewController
3. nd code below in the SceneDelegate.m
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)scene];
MainViewController *controller = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
self.window.backgroundColor = [UIColor redColor];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
}
2020년 9월 8일 화요일
Print whole matrix in Numpy
import sys
import numpy as np
np.set_printoptions(threshold=sys.maxsize)
// and then print the matrix what you want
print(np.arange(1000).reshape(2,5,100))
2020년 8월 3일 월요일
[Android] Google Social Login
2020년 7월 27일 월요일
Using Swift framework in an Objective-c project
https://marcinczenko.github.io/post/using-swift-frameworks-from-objective-c-target/
===============================================
=============== Swift Framework ===============
===============================================
Make a ExampleSwiftFramework framework. not Static Library
Add ExampleSwiftFramework.swift and put the code below
@objc
public class ExampleSwiftFrameworkClass : NSObject {
let message: String
@objc(init:)
public init(withHelloMessage message: String) {
self.message = message
}
@objc(sayHello)
public func sayHello() -> String {
return self.message
}
}
TARGETS->Build Settings
Mach-O : 'Dynamic Library'
Build Options->Always Embeded Swift Standard Libraries : No
Packaging->Defines Module : Yes
Apple Clang-Language-Modules->Enable Modules(C and Objective-C) : Yes
next to the upper left 'stop' icon. click framework and edit scheme->Run->Build Configuration=> Release
Click Product->Build
and you can see the built framework on the project navigato.
Right click at the file->Show in Finder
===============================================
============= Objective-C project =============
===============================================
Make an objective-C project
TARGETS->General
1. add the swift framework into the 'Frameworks, Libraries, and Embedded Content'
2. and then you can see 'Framework' folder in the project navigator.
3. remove the framework from the 'Frameworks, Libraries, and Embedded Content'
4. drag the framework.framework folder into the 'Framework' in the project navigator
TARGETS -> Build Settings(All, Combined taps)
Build Option -> Always Embed Swift Standard Libraries : No
TARGETS -> Build Phases
Click '+' and add New Copy Files Phase category
add the swift framework what you need and keep the default option(Code Sign On Copy : checked, Copy only when installing : unchecked)
put the code below in -(void)viewDidLoad
ExampleSwiftFrameworkClass *exam = [[ExampleSwiftFrameworkClass alloc] init:@"Test"];
NSLog(@"%@", [exam sayHello]);
2020년 7월 19일 일요일
Room migrations in Kotlin
To test you need two class//===============================================================// AppDatabase classDatabase(entities = [Song::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() { companion object {@Volatile private var INSTANCE: AppDatabase? = null fun getInstance(context: Context): AppDatabase = INSTANCE ?: synchronized(this) {INSTANCE ?: buildDatabase(context).also {INSTANCE = it }}private fun buildDatabase(context: Context) =Room.databaseBuilder(context.applicationContext,AppDatabase::class.java, "test.db").build()fun destroyInstance() {INSTANCE = null} }}
//===============================================================
// Entity class
// when the version was 1
@Entitydata class Song(
@PrimaryKey val id: Long, val title: String
)
//===============================================================
When you run an app with the database version 1after then you modified the Song class added 'tag' entity.@Entitydata class Song( @PrimaryKey val id: Long,val title: String,val tag: String // Added in version 2.)you should change the version number of AppDatabase class like below from 1 to 2Database(entities = [Song::class], version = 2, exportSchema = false)you also have to edit database builder like thisprivate fun buildDatabase(context: Context) = Room.databaseBuilder(context.applicationContext,AppDatabase::class.java, "terry.db") .addMigrations(MIGRATION_1_2).build()and add migration code or edit it in the Song class// Migration from 1 to 2, Room 2.1.0val MIGRATION_1_2 = object : Migration(1, 2) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL( "ALTER TABLE Song ADD COLUMN tag TEXT NOT NULL DEFAULT ''") } }That's all! :)